in reply to More File/Directory Trouble
Why are you doing this? I know, you are making sure Perl Does the Right Thing and you have been bitten by ( I am guessing here ) shell programming.open(FILE, ">folder/${name}/${date}.txt");
In Perl, legal variables names are must start with an alphabetic character or an underscore. After that, it can be lots of things. It cannot be, though, / or ".". Which means you can write that line as
which is easier on my poor eyes. It flows, it makes sense.open(FILE, ">folder/$name/$date.txt");
Of course, I also fall off the end of this statement. Especially when you open it for writing. You are not checking to see if you open the file. This will annoy you later, believe me. A wise monk ( or at least a monk who is tired of being bitten by this ) would say
which will not only protect you from trying to write to an unopened file, but it will also tell you why it didn't work.open(FILE, ">folder/$name/$date.txt") || die("Couldn't open file for w +riting: $!");
Of course, a stylish monk would take offense to all the parens in there. Actually, a stylish monk is really lazy and hates the cording necessary to make ( and ). So s/he would say instead
I would take this one step further and make the error message more informative and sayopen FILE, ">folder/$name/$date.txt" or die "Couldn't open file for re +ading:$!";
This would tell me what the code was trying to open so I could figure out what I screwed up this time.my $filename = "folder/$name/$date.txt"; open FILE, ">$filename" or die "Couldn't open $filename for writing: $ +!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: More File/Directory Trouble
by Fastolfe (Vicar) on Jul 29, 2000 at 19:48 UTC | |
by Fastolfe (Vicar) on Jul 29, 2000 at 19:53 UTC | |
|
RE: RE: More File/Directory Trouble
by Fastolfe (Vicar) on Jul 29, 2000 at 19:50 UTC |