lezek has asked for the wisdom of the Perl Monks concerning the following question:
Out of interest today i tried the following code to see what would happen:
open (my $f, '<', 'input.txt'); while (<$f>) { print; } close $f;
To my enormous surprise, it worked perfectly. I tried it again with two files open at a time, and it still worked. It seems that whatever you pass as a filehandle comes back with a different value for each file, and what's more that value is actually valid.
I've never seen this in any documentation anywhere, and indeed either the camel or llama book (can't remember which) talks about using seperate modules to simulate scoped filehandles, which the above would seem to suggest is unnecessary.
So, is there some reason doing what I just did is a bad idea?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: open (my $f, ....)
by philcrow (Priest) on Feb 16, 2006 at 17:09 UTC | |
by lezek (Initiate) on Feb 16, 2006 at 17:14 UTC | |
|
Re: open (my $f, ....)
by dorward (Curate) on Feb 16, 2006 at 17:10 UTC | |
by lezek (Initiate) on Feb 16, 2006 at 17:16 UTC | |
|
Re: open (my $f, ....)
by brian_d_foy (Abbot) on Feb 16, 2006 at 18:55 UTC |