in reply to Re: Re: How do you move within an array using foreach?
in thread How do you move within an array using foreach?

# please forgive me..there are the hashes.. %foo1 = ( a => "1", b => "2", c => "3", ); %foo2 = ( d => "4", e => "5", f => "6", );

Replies are listed 'Best First'.
Re: Re: Re: Re: How do you move within an array using foreach?
by jj808 (Hermit) on Oct 10, 2002 at 19:31 UTC
    How about something like this then:
    #! /usr/bin/perl -w use strict; use Data::Dumper; my @lines = (<>); my %data = (); my $token = ''; foreach (@lines) { if (/\[(\w+)\]/) { $token = $1; } if (/(\w+)=(\w+)/) { $data{$token}->{$1} = $2; } } print Dumper(\%data);
    The output is:
    $VAR1 = { 'foo2' => { 'e' => '5', 'f' => '6', 'd' => '4' }, 'foo' => { 'a' => '1', 'b' => '2', 'c' => '3' } };
    Not 100% what you want - this creates a hash of hashes - but still useable.

    JJ