P
Pietro
Hallo, I made a little script that sort the lines of a file:
#! /usr/bin/perl
sub numerically {$a <=> $b;}
@array = <>;
@array = sort numerically (@array);
print (@array);
Maybe the code is not so good, but why if I give thi input file:
1.3.5.6
1.1.2.4
111.222.444.555
1.2.5.6
11.22.44.55
1.2.3.4
11.23.66.77
11.22.33.44
111.222.333.444
11.22.44.55
111.223.333.444
11.22.33.44
1.2.3.4
11.22.22.22
11.22.55.66
1.2.4.5
111.222.555.666
1.1.2.3
1.3.4.5
The result is this:
1.1.2.4
1.1.2.3
1.2.5.6
1.2.3.4
1.2.3.4
1.2.4.5
1.3.5.6
1.3.4.5
11.22.44.55
11.22.33.44
11.22.44.55
11.22.33.44
11.22.22.22
11.22.55.66
11.23.66.77
111.222.444.555
111.222.333.444
111.222.555.666
111.223.333.444
As I see perl sots only the first two field delimited by a ".", the others
are inserted as a fifo, first line encountered first line wrote in output,
why doesn't perl compare all the line?
Thanks, Pietro.
#! /usr/bin/perl
sub numerically {$a <=> $b;}
@array = <>;
@array = sort numerically (@array);
print (@array);
Maybe the code is not so good, but why if I give thi input file:
1.3.5.6
1.1.2.4
111.222.444.555
1.2.5.6
11.22.44.55
1.2.3.4
11.23.66.77
11.22.33.44
111.222.333.444
11.22.44.55
111.223.333.444
11.22.33.44
1.2.3.4
11.22.22.22
11.22.55.66
1.2.4.5
111.222.555.666
1.1.2.3
1.3.4.5
The result is this:
1.1.2.4
1.1.2.3
1.2.5.6
1.2.3.4
1.2.3.4
1.2.4.5
1.3.5.6
1.3.4.5
11.22.44.55
11.22.33.44
11.22.44.55
11.22.33.44
11.22.22.22
11.22.55.66
11.23.66.77
111.222.444.555
111.222.333.444
111.222.555.666
111.223.333.444
As I see perl sots only the first two field delimited by a ".", the others
are inserted as a fifo, first line encountered first line wrote in output,
why doesn't perl compare all the line?
Thanks, Pietro.