Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Perl fIle handles

by mikeraz (Friar)
on Jun 15, 2011 at 17:16 UTC ( [id://909814]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl fIle handles
in thread Perl fIle handles

But it is best to open the lexical file handle directly, and the three parameter form of open when write mode:

open my $fh, $file or die "Can't open $file::$!";
Did you mean
 open my $fh, (some mode string of + < > >>), $file or die "Can't open $file::$!";
??


Be Appropriate && Follow Your Curiosity

Replies are listed 'Best First'.
Re^3: Perl fIle handles
by wind (Priest) on Jun 15, 2011 at 17:55 UTC

    No, actually I just wanted to demonstrate that he could include the my within the open statement, but I can see how you could think I was implying something else. It was up to him to simply read the docs for open to see how to use the three parameter form.

    Also, I'd advise against ever using the three parameter form of open when wanting read mode. It's much better to just let read mode be assumed so you don't risk putting the symbol in the wrong direction and overwriting your file.

    Just my .02

      Also, I'd advise against ever using the three parameter form of open when wanting read mode. It's much better to just let read mode be assumed so you don't risk putting the symbol in the wrong direction and overwriting your file.

      And risk having the second arg contain something scary?
      $file = '> somefile';

        That's a fair point, although I'm not sure I would qualify that as "scary".

        Given most of the file operations I perform are ones where I'm specifying the filename passed in the variable, I don't see this as a big risk. However, if there was ever a point where the file was specified in by the user and not validated in any way, then doing the three parameter form of read mode would be wise.

        For me at least, the right of being lazy is going to win out for this small risk otherwise. I find mistyping to be a bigger worry then intentional mischief.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://909814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found