Can someone assist me with getting the correct syntax to sort this array please? I've tried all sorts and searched past threads but have not found the right answer.
I have a very complex and lengthy script that queries a database and eventually ends up with me having data in this format (this is 3 lines of data below - it doesn't display well so I have prefixed each line for clarity):
I need to sort the lines based on the third field in each line.
The code above simulates the data structure I have i.e $array[$p][1] $array[$p][2] $array[$p][3] for each line.
It currently gives the following output:
I need to sort each line based on $array[$p][3]so that it displays:
Can anyone help with the syntax to do this?
I have a very complex and lengthy script that queries a database and eventually ends up with me having data in this format (this is 3 lines of data below - it doesn't display well so I have prefixed each line for clarity):
Code:
<line1> MOVE_top\general\major\captain\corp%1@MOVE_top%2.0_BL.01 corp%1:dir:pit01t MOVE_top\general\major\captain
<line 2> MOVE_top\general\major%1@MOVE_top%2.0_BL.01 major%1:dir:pit01t MOVE_top\general
<line3> MOVE_top\general\major\captain%1@MOVE_top%2.0_BL.01 captain%1:dir:pit01t MOVE_top\general\major
I need to sort the lines based on the third field in each line.
Code:
#!/usr/contrib/bin/perl
use strict;
my @array;
my $x;
my $p=1;
while (<DATA>) {
chomp;
($array[$p][1], $array[$p][2], $array[$p][3],) = split /\s+/;
$p++;
}
close DATA;
for ($x=1;$x<$p;$x++) {
#<do processing here: print to show line order>
print "$array[$x][3]\n";
}
__DATA__
MOVE_top\general\major\captain\corp%1@MOVE_top%2.0_BL.01 corp%1:dir:pit01t MOVE_top\general\major\captain
MOVE_top\general\major%1@MOVE_top%2.0_BL.01 major%1:dir:pit01t MOVE_top\general
MOVE_top\general\major\captain%1@MOVE_top%2.0_BL.01 captain%1:dir:pit01t MOVE_top\general\major
The code above simulates the data structure I have i.e $array[$p][1] $array[$p][2] $array[$p][3] for each line.
It currently gives the following output:
Code:
MOVE_top\general\major\captain
MOVE_top\general
MOVE_top\general\major
I need to sort each line based on $array[$p][3]so that it displays:
Code:
MOVE_top\general
MOVE_top\general\major
MOVE_top\general\major\captain
Can anyone help with the syntax to do this?