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

Re: Filehandles named with a variable

Thread Previous | Thread Next
Peter Scott
April 3, 2002 10:43
Re: Filehandles named with a variable
Message ID:
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
>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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About