in reply to Re: parsing text file into a hash?
in thread parsing text file into a hash?

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

Replies are listed 'Best First'.
Re: Re: Re: parsing text file into a hash?
by ralfthewise (Sexton) on Jun 15, 2001 at 22:53 UTC
    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; }