M. Lewis <mailto:[EMAIL PROTECTED]> wrote:
: open my $fh, '<', $input_file or die qq(Cannot open "$input_file": $!); [snip] : Charles opted to use qq() which cause him to have to enclose the : $input_file in "". $input_file is in quotes just in case I tried to open a file that has leading or trailing spaces in the name. I once wrote a script which opened a number of files and I couldn't figure out why one file was not opening. (It was early morning, as I recall.) After adding the quotes I found stray white space in the name. (I think I was splitting white space with "split /\s/;" instead of "split ' ';" and the leading space on the first argument was left on.) Here's a very simple example. In my directory "in.txt" exists, but not " in.txt". (Note: I used "warn" here to get all the error messages. Normally we "die" on fatal errors.) #!/usr/bin/perl use strict; use warnings; #use diagnostics; my $file = ' in.txt'; open my $fh, '<', $file or warn qq(Cannot open "$file": $!); close $fh or warn qq(Cannot close "$file": $!); warn "\n"; open $fh, '<', $file or warn qq(Cannot open $file: $!); close $fh or warn qq(Cannot close $file: $!); __END__ Cannot open " in.txt": No such file or directory at bb.pl line 9. Cannot close " in.txt": Bad file descriptor at bb.pl line 11. Cannot open in.txt: No such file or directory at bb.pl line 13. Cannot close in.txt: Bad file descriptor at bb.pl line 15. At the end of a long programming night, in the early morning hours, as the text on the screen seems to be moving, the first set of errors made debugging easier. You may be surprised how many times I have tested example code for an answer on this list and found this. :) Cannot open "": No such file or directory at . . . The quotes around the file name are not needed for interpolation. (The qq() operator does that.) They just aid me in picking up extra white space and have saved me some debugging time in the past. I wrap the hole message in qq() because escaped quotes '\"' look so ugly (to me). 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>