On May 17, Yacketta,Ronald J said:

>backint:maple aspen pine
>online:orange palm cherry
>
>is it possible to read in this file and what ever is before the : would
>become the name of
>the array? 

The key is, DON'T DO THAT.  Don't make arrays with names you don't know
ahead of time.  It's best to keep those ANONYMOUS.

  while (<FILE>) {
    my ($name, $list) = split /:/, 2;
    $servers{$name} = [ split ' ', $list ];
  }

That makes a hash, %servers, with the names of the would-be arrays as
keys.  The values in the hash are array references.

Then, instead of using an array, use @{ $servers{$name} }.  It's also an
array, and far saner than making an array with a name you don't know.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
*** I need a publisher for my book "Learning Perl Regular Expressions" ***

Reply via email to