You could read your data into a hash table to make things a
little easier on yourself, I think:
use warnings;
use strict;
use Data::Dumper;
my @accounts = ("A x1 B y1 C z1 D v1 E w1 F",
"A x2 B y2 C zzz2 D v2 E w2 F",
"A x3 B y3 C z3 D v3 E w3 F",
"A x4 B y4 C z4 D v4 E wwww4 F",
"A x5 B y5 C z5 D v5 E w5 F",
"A x6 B y6 C z6 D v6 E F");
my %fields = map { $_ => 1 } qw/A B C D E F/;
my $cur_field;
my %hash;
foreach ( @accounts ) {
foreach ( split ) {
$cur_field = $_ if exists $fields{$_};
push @{$hash{$cur_field}}, $_
if $_ ne $cur_field;
}
}
print Dumper \%hash;
__END__
$VAR1 = {
'A' => [
'x1',
'x2',
'x3',
'x4',
'x5',
'x6'
],
'B' => [
'y1',
'y2',
'y3',
'y4',
'y5',
'y6'
],
'C' => [
'z1',
'zzz2',
'z3',
'z4',
'z5',
'z6'
],
'D' => [
'v1',
'v2',
'v3',
'v4',
'v5',
'v6'
],
'E' => [
'w1',
'w2',
'w3',
'wwww4',
'w5'
]
};
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.