Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Naming file handles with variables?

by QM (Vicar)
on May 01, 2009 at 03:53 UTC ( #761211=note: print w/ replies, xml ) Need Help??


in reply to Re: Naming file handles with variables?
in thread Naming file handles with variables?

Should that be [$filename] here?

for my $filename (@fileNames) { open $fileHandles[$filename], '<', $filename or die "Can't open $f +ilename: $!";

-QM
--
Quantum Mechanics: The dreams stuff is made of


Comment on Re^2: Naming file handles with variables?
Select or Download Code
Re^3: Naming file handles with variables?
by GrandFather (Cardinal) on May 01, 2009 at 05:19 UTC

    I don't thinks so. open $fileHandles[@fileHandles], ... 'creates' a new array element for the new file handle. You could instead:

    open my $newFileHandle, ...; push @fileHandles, $newFileHandle;

    to achieve the same effect.

    If fileHandles were a hash instead of an array then keying by the file name would be appropriate however.


    True laziness is hard work
      OIC. Scalar context giving the next index. Hadn't seen this before, but it's interesting.

      I don't think I would use this myself, as I don't know who would be maintaining my code. I'd prefer the alternative you gave for transparency. Doubly preferred, given the OP's apparent sophistication level.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        I agree with you. I probably should have used the less esoteric version given the OP's demonstrated level of expertise. However, you now know a new technique, so maybe pushing the edge of the envelope a little was the right thing after all. ;)


        True laziness is hard work

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-10-23 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (124 votes), past polls