develooper Front page | perl.beginners | Postings from April 2002

Re: Filehandles named with a variable

Thread Previous | Thread Next
From:
Peter Scott
Date:
April 3, 2002 10:43
Subject:
Re: Filehandles named with a variable
Message ID:
4.3.2.7.2.20020403104050.00b2ee80@shell2.webquarry.com
At 03:48 PM 4/2/02 -0600, Mr Hash wrote:
>So, I'm trying to 'open ($1,">>$file")', where $1 is a string like
>"cbQosCMPrePolicyPktOverflow".
>
>Obviously, with use strict this does not work. How can I make it work? I
>need arbitrarily named filehandles. I know, it could get rended with
>gobbleworts if the data gets out of hand...

Maybe I'm missing something, but why not

         open my $fh, ">>$file";

You're constructing a unique string in $1 just so you can have a new 
filehandle?  Using open my $fh (not sure whether this was a 5.005-ism or a 
5.6-ism) you get a new lexical filehandle which seems to be what you want.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About