On Wed, 17 Nov 2004 16:08:07 -0600, Shashank Khanvilkar wrote:
> I have data in the following format
>
> A
> B=2
> C=3
> B
> S=2
> T=10
> ...
>
>
> I need to populate a hash data structure (%graph) in perl so that %graph
> will have the form
> %graph = (
>
> A => {B=>2,C=>3},
>
> B => {S=>2,T=>10}
> }
What have you tried so far? It's hard to spot where's your problem without
to know something about.
However the following snippet seems to do what you want:
#!/usr/bin/perl
use strict;
use warnings;
my %graph;
my $sec;
while (<DATA>) {
chomp;
/^(\w+)/ and $sec = $1
or /(\w+)=(\d+)/ and $graph{$sec}->{$1} = $2;
}
use Data:

umper;
print Dumper(\%graph);
__DATA__
A
B=2
C=3
B
S=2
T=10
Greetings,
Janek