You could keep everything in the same hash :)
#!/usr/bin/perl
use strict; # https://perlmonks.org/?node_id=11106277
use warnings;
my $order = '*order*';
my %hash;
while( <DATA> )
{
my ($vitem, $project, $segments) = /(\w+),(\w+:\d+)\|(.*)/;
exists $hash{$project} or push @{$hash{$order}}, $project;
exists $hash{$project}{$vitem} or push @{$hash{$project}{$order}}, $
+vitem;
push @{$hash{$project}{$vitem}}, split /;/, $segments;
}
for my $project ( @{ $hash{$order} } )
{
print "Project: $project\n";
for my $vitem ( @{ $hash{$project}{$order} } )
{
print " Vitem: $vitem\n";
for my $segment ( @{ $hash{$project}{$vitem} } )
{
print " Segment: $segment\n";
}
}
}
__DATA__
J_071117,BM:3|12.0-25.2;32.9-88.0
J_070424,BM:3|625-920;1017.905-1178
J_021212,BB:1|123-166;409-455
070526,SWT:1|53.160-59.320;77.720-86.120;370.800-416.800
070609,SWT:1|713.760-1159.200
070616a,SWT:1|0.0-652.0
070616b,SWT:1|401.40-461.800;483.160-490.640;503.400-595.200;602.440-6
+95.400;699.200-882.400
J_071019a,SWT:1|372.925-910.385;927.620-1038.830
J_071019b,SWT:1|268.15-808.330
J_071025,SWT:1|936.215-1659.635
071123_F,SWT:1|45.4550-81.665
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.