Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

I/O > Error Checking - Pg. 208

The only time you should use the two-argument form of open is if you need to open a stream to or from the standard I/O streams: open my $stdin, '<-' or croak "Can't open stdin: $OS_ERROR"; open my $stdout, '>-' or croak "Can't open stdout: $OS_ERROR"; The three-argument forms: open my $stdin, '<', '-' or croak "Can't open '-': $OS_ERROR"; open my $stdout, '>', '-' or croak "Can't open '-': $OS_ERROR"; don't have the same special magic; they simply attempt to open a file named " - " for reading or writing. As an alternative to using open at all, you can also use Perl's object-oriented I/O interface to open files via the standard IO::File module. For example, the earlier log system example could also be written: # Log system uses a weird but distinctive naming scheme... Readonly my $ACTIVE_LOG => '>temp.log<'; Readonly my $STATIC_LOG => '>perm.log<'; # and later... use IO::File; my $active = or croak my $static = or croak IO::File->new($ACTIVE_LOG, "Can't open '$ACTIVE_LOG': IO::File->new($STATIC_LOG, "Can't open '$STATIC_LOG': '<') $OS_ERROR"; '>') $OS_ERROR";