[BNE-PM] The Perl one-liner

Derek Thomson derek at wedgetail.com
Thu Sep 19 22:59:49 CDT 2002


Don.Simonetta at mincom.com wrote:
> Totally agree with you Derek.
> My only comment is if you don't want to go to the trouble of importing
> DirHandle, you could use the standard perl functions of opendir &
> readdir.

I've gotten so used to using DirHandle and IO::File, it just came out 
that way!

I *always* use these, as the whole file handle identifier thing is a 
kludge. When you say:

open FILE, "< file";

... how do you then pass FILE to a function? How do you put it into an 
array or a hash? You can't, unless you pass the symbol table entry for 
the identifier (the "typeglob"). This is so much low-level hacking for 
such a simple thing, and is such a stumbling block to learners, that I 
just teach:

$file = IO::File->new("< file");

... right from the start. Since $file is just a reference, you can pass 
it to functions, assign it to other variables, put it in arrays and 
hashes, and the world is a better and saner place. The "read line" 
operator "<>" even works with this, as in "while (<$file>) { ... }", so 
there's no reason that I can see to use the older notation.

--
D.




More information about the Brisbane-pm mailing list