Hi to all,
Having a problem with sorting.
My file "client.txt" has lines of 2 fields,
in the form of:
8564|Jansens
3657|Vandamme
1235|Fullmark
...etc
I would like to sort this file on the first field
so that this file is rewritten as:
1235|Fullmark
3657|Vandamme
8564|Jansens
I made the following code but it does not work
and returns an error
Can someone help me please.
=============================================
# Variables used
$clientpath = "/home/mysite/public_html/client.txt";
$flock = "1";
# Sorting Code
open (clientfile, "$clientpath");
if ($flock == 1) {flock(clientfile, 2);}
while (<clientfile>) {
$line = $_;
chop ($line) if ($line =~ /\n$/);@fields = split (/\|/, $line);
foreach $line (sort { $line{$a} <=> $line{$b} })
}
close (clientfile);
==============================================
Regards,
Sanuk
Having a problem with sorting.
My file "client.txt" has lines of 2 fields,
in the form of:
8564|Jansens
3657|Vandamme
1235|Fullmark
...etc
I would like to sort this file on the first field
so that this file is rewritten as:
1235|Fullmark
3657|Vandamme
8564|Jansens
I made the following code but it does not work
and returns an error
Can someone help me please.
=============================================
# Variables used
$clientpath = "/home/mysite/public_html/client.txt";
$flock = "1";
# Sorting Code
open (clientfile, "$clientpath");
if ($flock == 1) {flock(clientfile, 2);}
while (<clientfile>) {
$line = $_;
chop ($line) if ($line =~ /\n$/);@fields = split (/\|/, $line);
foreach $line (sort { $line{$a} <=> $line{$b} })
}
close (clientfile);
==============================================
Regards,
Sanuk