Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Re: How do you move within an array using foreach?

by jj808 (Hermit)
on Oct 10, 2002 at 19:31 UTC ( [id://204301]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://204301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found