Re: open my $fh, MODE, FILE vs. open my $fh, "MODE FILE"
by hardburn (Abbot) on Feb 02, 2004 at 21:48 UTC
|
open FH, MODE, FILE form is prefered, as long as you can guarentee the use of perl 5.6 or higher. That mode will make it a lot harder to accidentally open up a file the wrong mode (either due to a mis-typed filename or bad user input).
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
: () { :|:& };:
Note: All code is untested, unless otherwise stated
| [reply] [d/l] [select] |
|
|
To clarify, modules and scripts for which backwards compatablilty with previous perls is required shoud refrain from using the three arg form. Just FYI.
| [reply] |
Re: open my $fh, MODE, FILE vs. open my $fh, "MODE FILE"
by ysth (Canon) on Feb 02, 2004 at 22:06 UTC
|
| [reply] |
|
|
There's more to it. Whitespace on both sides of the filename gets stripped. Tough luck if your filename actually has whitespace on either end of its name...
From perldoc -f open:
The filename passed to open will have leading and trailing whitespace deleted, and the normal redirection characters honored.
| [reply] |
|
|
Tough luck if your filename actually has whitespace on either end of its name
If you have filenames like that, you'll have trouble
with more than just Perl. Even whitespace in the
middle of filenames has a tendency to break things.
I would personally be more concerned about the backward
compatibility. There are a lot of people out there
still using 5.003 for one reason or another.
Of course, if you're using newer Perl features anyway,
like unicode or threads, then that consideration
becomes moot and you may as well use the three-arg form.
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
| [reply] [d/l] |
Re: open my $fh, MODE, FILE vs. open my $fh, "MODE FILE"
by Anonymous Monk on Feb 02, 2004 at 22:23 UTC
|
/me sighs and blushes a bit.
Remind me next time to make sure that I post things like this on a tab where I'm logged in -- this was my post, I somehow posted it under a tab where I hadn't logged in. Thanks for the information, everyone. | [reply] |
|
|
Dear AnonyMonk,
This is just a friendly reminder, as per your request, to log in. First you need to log in before you post and then again you need to log in before you post a message to let us know that it was your post in the first place :P
On a serious note, I find it easier to tell what I'm doing if I have my own style sheet activated in my User Settings. Then I can tell my 'logged in' tab from my annonytab. If you don't want a full blown style sheet, consider just applying a background color. Then you can quickly see which is which.
Cheers!
BigLug
| [reply] |