Hello
I have a file with data like this test.txt:
I would like to know how to read from that file and display the data sorted by any column eg State
Right now I just have this:
Thanks in advance.
I have a file with data like this test.txt:
Code:
1 3423 John Michael 33 NY
2 5345 Silvia Goodman 12 FL
3 5783 Lewis Nieto 41 TX
4 9435 Martha Fuchs 36 NJ
5 4721 Mark Brown 28 CA
I would like to know how to read from that file and display the data sorted by any column eg State
Code:
5 4721 Mark Brown 28 CA
2 5345 Silvia Goodman 12 FL
4 9435 Martha Fuchs 36 NJ
1 3423 John Michael 33 NY
3 5783 Lewis Nieto 41 TX
Right now I just have this:
Code:
$file_inp = 'c:\daily\test.txt';
open(HANDLE_FILEINP, "<$file_inp") || die "Couldn't open FILEINP.\n";
$prev_line = " ";
while($cur_line = <HANDLE_FILEINP>)
{
$prev_line = $cur_line;
$prev_line_chomped = $prev_line;
chomp($prev_line_chomped);
@field_data = split(/\t/, $prev_line_chomped);
print "$prev_line"
}
close(HANDLE_FILEINP);
print(" \n");
Thanks in advance.