in reply to Re^2: Question about binary file I/O
in thread Question about binary file I/O
I had "use strict" in the program originally, but it seemed to do nothing but cause trouble; it mostly meant that I had to put "my" before almost every variable, so I just got rid of it. I'm also not sure what you mean by lexical file handles and 3-argument open.The "my" is actually very useful because, apart from catching typos in misspelt variable names, it limits the scope of the variable. A variable declared with "my" is known as a lexical variable because it has lexical scope; that is, its name is known from the point of declaration to the end of the block it is declared in (or end of file if not declared in a block). Hence my recommendation to use lexical file handles (e.g. my $fhin) rather than your global variable bareword file handle IN.
Using lexical file handles is better style because:
As for why the three-argument form of open is preferred, note that the old two-argument form of open is subject to various security exploits as described at Opening files securely in Perl.
See also the first four items of Perl Best Practices Chapter 10 (I/O), namely:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Question about binary file I/O
by TheMartianGeek (Acolyte) on Feb 06, 2011 at 16:10 UTC | |
|
Re^4: Question about binary file I/O
by TheMartianGeek (Acolyte) on Feb 06, 2011 at 06:05 UTC | |
by eyepopslikeamosquito (Archbishop) on Feb 06, 2011 at 07:18 UTC | |
|
Re^7: Question about binary file I/O
by TheMartianGeek (Acolyte) on Mar 02, 2011 at 05:21 UTC | |
by roboticus (Chancellor) on Mar 02, 2011 at 11:13 UTC |