Offer Kaye <mailto:[EMAIL PROTECTED]> wrote:

: my $infile = "file.txt";
: open (INPUT, $infile) or die "$0 error, can't open $infile for reading:
$!\n";

: The "open" line is essentially the same as yours, I simply beefed-up
: the error message (read "perldoc perlvar" for more info about $0 and
: $!).

    Using a "\n" after the $! variable suppresses information about
the error. Let's look at a simple test from a script named a.pl.


#!/usr/bin/perl

use strict;
use warnings;

my $infile = 'Q:\l';
open (INPUT, $infile) or die "$0 error, can't open $infile for reading:
$!\n";
__END__

Yields:
a.pl error, can't open Q:\l for reading: No such file or directory


#!/usr/bin/perl

use strict;
use warnings;

my $file = 'Q:\l';
open FH, $file or die qq(Cannot open "$file": $!);

__END__

Yields:
Cannot open "Q:\l": No such file or directory at a.pl line 8.

    Notice that we lose line number information when using "\n"
after $!.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328











-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to