in reply to Re: How to Order an Array's Elements to Match Another Array's Element Order
in thread How to Order an Array's Elements to Match Another Array's Element Order
With arrays for ordering instead of IxHashes:
#!/usr/bin/perl use warnings; use strict; my %hash; my @projects; my %vitems; while (my $buf = <DATA>) { chomp($buf); my ($vitem, $project_info) = split(/,/, $buf); my ($project_name, $segment_info) = split(/\|/, $project_info); my (@segments) = split(/;/, $segment_info); push @projects, $project_name unless exists $hash{$project_name}; push @{$vitems{$project_name}}, $vitem; push(@{$hash{$project_name}{$vitem}}, @segments); } for my $proj (@projects) { print "Project: $proj\n"; for my $vi (@{$vitems{$proj}}) { print " VItem: $vi\n"; for my $seg (@{$hash{$proj}{$vi}}) { print " Segment: $seg\n"; } } } exit(0); # ----------- __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
|
|---|