It is good that you are checking the sucess of your
open call, but as
you discovered, your error message didn't help very much.
Perl provides some more tools to help you though.
Here's a way to do it that provides more explicit
assistance when something goes wrong:
use strict;
use warnings;
my $filename = "C:/mlb_boxscore107238$4820.txt";
open(INPUT, '<'.$filename) or die "Can't open $filename: $!\n";
Which produces:
Name "main::INPUT" used only once: possible typo at test.pl line 4.
Use of uninitialized value in concatenation (.) at test.pl line 3.
Can't open C:/mlb_boxscore107238.txt: No such file or directory
Note the following:
- use strict generated the message about INPUT only being used once, which is handy
in case you typed while(<INPT>) later on
- use warnings generated the warning about the uninitialized value at line 3, which would
lead you to ask "what concatenation" and possibly then notice the $ inside double quotes made Perl look for a variable there.
Just to keep things simple, I try to always use single quotes unless I really need interpolation. That also
makes the double quotes act as flags to other readers, alerting them to interpolation.
- the third line of output came from the die but this time it contains quite a bit more information
than before
- Perl's interpretation of the problematic filename (note no $ present)
- The actual error message that what you asked for doesn't exist (more explicit than "can't open")
I hope this helps!
--
I'd like to be able to assign to an luser