> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 9:57 AM
> To: [EMAIL PROTECTED]
> Subject: generating arrays on the fly
> 
> 
> hi,
> 
> what I'm wanting to do is generate an array named after a 
> string that is
> found in a text file.
> 
> i.e something like this:
> if ($line=~(/^\[\[(\w+)\]\]/)){
> @$1=();   #this is the line I want to acheive my aim with!
> }
> 
> I know the syntax is wrong, but hopefully it explains what 
> I'm trying to
> do, any clues?

No, you don't want to do that. Suppose the string in your text file is INC
or ISA. You'll trash those global arrays, or perhaps other arrays in your
script.

Use a hash to hold these arrays instead. The hash keys can be the names from
your file. Then you're safe.

my %h;

if ($line=~(/^\[\[(\w+)\]\]/)){
   $h{$1} = []; # initalize to an empty array
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to