This appears to do what you want:
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my ( $number, %accounts ); while ( <DATA> ) { chomp; if ( /^A,/ ) { ( undef, $number, my @fields ) = split /,/, $_, -1; @{ $accounts{ $number } }{ qw/ surname firstname job balance / + } = @fields; } elsif ( /^B,/ ) { my $transaction = ( split /,/ )[ 1 ]; push @{ $accounts{ $number }{ transactions } }, $transaction; } } print Dumper \%accounts; __DATA__ A,01,Newton,Issac,Physics, 5.6 B,144.56 B,1034.65 B,12.23 A,34,Einstein,Albert,Physics,12.22 B,2346.89 B,876.23 B,7656.81 B,745.21 B,25.63 B,89.56 B,7789.23 A,78,Feynman,Richard,Physics,-17.34 B,7412.36 B,2589.35 B,95.32 B,12.85 B,789.68
In reply to Re: read multiple record data and populate in a new data stucture
by jwkrahn
in thread read multiple record data and populate in a new data stucture
by fseng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |