in reply to Re: Help creating a data structure out of a delimited string
in thread Help creating a data structure out of a delimited string

my @data; for my $set (split /#/, $patterns) { my @vals = split /\s+/, $set; my %hash; for my $i (0 .. $#vals) { $hash{$names[$i]} = $vals[$i]; } push @data, \%hash; }
my @data; for ( split /#/, $patterns ) { my %hash; @hash{ @names } = split; push @data, \%hash; }

Replies are listed 'Best First'.
Re^3: Help creating a data structure out of a delimited string
by raybies (Chaplain) on Dec 15, 2010 at 20:03 UTC

    Dang. Can you really do that?

    Accessing a hash with the array op like that? ANd how do you garantee they map value to key?

    I bow to your perliness.

      Yes, it is called a hash slice.    And, the for loop in toolic's code assumed the same mapping.

        I just typed it in just to play with (and remember) it. Very cool. Thanks! --Ray
Re^3: Help creating a data structure out of a delimited string
by happy.barney (Friar) on Dec 16, 2010 at 13:24 UTC
    my $h = {}; my @data = map {{%{@$h{@names} = split, $h}}} split '#', $patterns;