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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.