Perl Tutorial : Perl data types
Perl Tutorial : Perl Operators
Perl Tutorial : Perl loops
Perl Tutorial : Perl Conditionals
Perl Tutorial : Perl Subroutines
Perl Tutorial : Perl regex
Perl Tutorial : Perl Files
Perl Tutorial : Perl & Databases
Perl Tutorial : Perl OOPs
Perl Tutorial : Perl signals
Perl Tutorial : Perl threads
Perl Tutorial : Perl Debugging

Introcution to Perl CGI

Introduction to modperl
Home >> perlexamples >>

handling Errors in perl

Use the standard means of handling Perl errors by using the Perl eval statement to analyze errors. Use the following example:
eval{open(FILE, $file);};
   if ($@)
      {
      print "Error opening file. Error: $@\n";
      }
else
   {
      # continue without error ...
   }

die

Outside an eval(), prints the value of LIST to STDERR and exits with the current value of $! (errno). If $! is 0, exits with the value of ($? >> 8) (backtick `command` status). If ($? >> 8) is 0, exits with 255. Inside an eval(), the error message is stuffed into $@ and the eval() is terminated with the undefined value. This makes die() the way to raise an exception.

Equivalent examples:
die "Can't cd to /etc/passwd: $!\n" unless chdir '/etc/passwd';
    chdir '/etc/passwd' or die "Can't cd to /etc/passwd: $!\n"

Perl functions

scalars and strings

lc
ord

regex (regular expressions)

arrays

shift
split

More..

eval
Share |

How to include module in perl?
number of matches in regex
Perl Data Dumper
perl: How to parse config file

Perl examples

  • How to use Data::Dumper?
  • How to parse config file?
  • Include external module in perl..
  • Download perl

    download stable version of perl
    Perl 5.10.1
    Perl interview Questions
    sed tutorial
    awk tutorial

    Join us on Google Groups

    Subscribe to perl
    Email:
    Visit this group
    Perl Jobs


    privacy | sitemap | disclaim | contact us
    © 2009 perlhome.com