in reply to Complex Data Structure
Show us a small sample of your data. Your current structure looks very unlikely to be best. If all you want to be able to do is sort the data in some fashion then consider:
use strict; use warnings; my $data = <<DATA; 1,2,3,4 2,3,4,1 3,4,4,2 4,1,2,3 DATA my @rows; open my $inFile, '<', \$data; while (<$inFile>) { chomp; push @rows, [split ',']; } close $inFile; print join (',', @$_), "\n" for sort mySort @rows; sub mySort { return $a->[1] <=> $b->[1] || $a->[3] <=> $b->[3] || $a->[2] <=> $b->[2] || $a->[0] <=> $b->[0]; }
Prints:
4,1,2,3 1,2,3,4 2,3,4,1 3,4,4,2
Which uses an AoA, sort and a user defined sort sub to get the rows sorted by arbitrary columns.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Complex Data Structure
by sesemin (Beadle) on Sep 15, 2008 at 00:27 UTC |