in reply to parsing text file into a hash?

You are looking for symbolic references, which means not using 'use strict', which is usually a bad idea. Why not store all the data in one hash of hashes?
use strict; my %names; while (<>) { my ($label, $name1, $name2, $name3, $name4) = split /:/; $names{$label}{$name1} = $name2; $names{$label}{$name3} = $name4; }
And the non strict (bad, dangerous, don't do this) version:
# Untested, because I rarely use symbolic refs :) while (<>) { my ($label, $name1, $name2, $name3, $name4) = split /:/; $$label{$name1} = $name2; $$label{name3} = $name4; }

Replies are listed 'Best First'.
Re: Re: parsing text file into a hash?
by Everlasting God (Beadle) on Jun 15, 2001 at 22:22 UTC
    That won't produce quite what he specifies:
    yours makes %names = name => bob => jane joe => sue name2 => john => me oh => my
    but his text seems to say he wants this:
    yours makes %names = name => first => bob second => jane third => joe fourth => sue name2 => first => john second => me third => oh fourth => my
    if this is really what is wanted, try this slight change:
    use strict; my %names; while (<>) { my ($label, $name1, $name2, $name3, $name4) = split /:/; $names{$label}{"first"} = {$name1} $names{$label}{"second"} = $name2; $names{$label}{"third"} = {$name3} $names{$label}{"fourth"} = $name4; }
    'The fickle fascination of and Everlasting God' - Billy Corgan, The Smashing Pumpkins
      Hey, I couldn't get it to compile until I changed the following
      {
      my ($label, $name1, $name2, $name3, $name4) = split /:/;
      $names{$label}{"first"} = $name1;
      $names{$label}{"second"} = $name2;
      $names{$label}{"third"} = $name3;
      $names{$label}{"fourth"} = $name4;
      }
      ...note the changes on $name1 and $name3....{$namex} to $namex;. I'm new at this, so should I have just left it alone? Is there something I just don't know? john
        Sorry, I guess I didn't read too closely the first time. at least you got the idea. But if that's what you want, you could do this:
        my %names; { my ($label, @names) = split /:/; @{$names{$label}}{qw(first second third fourth)} = @names; }