How would you trap error occurred in the perl program/file?

Answer Posted / shah faisal

#Ist trapping the error in a block
eval {
# perl code goes here
};

if ($@) { # $@ is a special variable containing the error
if any else blank
print "Print your own error If u want";
}

# 2nd
# use if or unless for a loop ;ike below
if(chk some condition)
{
die"$!\n"; # if the condition success
}
system generated error is printed and the scirpt is exited
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List the prefix dereferencer in Perl.

570


How will you get the count of parameters passed to a perl subroutine?

538


Write a cgi program to show the header part?

526


What are the advantages of perl programming?

536


How we can navigate the xml documents?

535






How can you replace the characters from a string and save the number of replacements?

510


You want to download the contents of a url with perl. How would you do that?

505


How to add elements in a hash in perl?

513


how to connect cisco switch uisng perl script

3384


Explain what is lvalue?

604


You want to empty an array. How would you do that?

478


How do you you check the return code of a command in perl?

587


How do I debug a perl program?

520


What are the various file operations in perl. Explain with example.

516


Explain chomp?

515