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

RE: Filehandles named with a variable

Thread Previous | Thread Next
From:
Timothy Johnson
Date:
April 2, 2002 14:38
Subject:
RE: Filehandles named with a variable
Message ID:
C0FD5BECE2F0C84EAA97D7300A500D5002581230@SMILEY

You REALLY shouldn't use $1 for a variable name, though, since it has a
special meaning.

-----Original Message-----
From: David Gray [mailto:david_gray@3b2.com]
Sent: Tuesday, April 02, 2002 2:33 PM
To: core@enodev.com; beginners@perl.org
Subject: RE: Filehandles named with a variable


> 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...

Have you tried using eval, like:

eval "open ($1 ">>$file");select $1";

One caveat: you might end up using a lot of eval statements, which will
probably slow down your code.

Hope that helps,

 -dave



-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

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