R
Robin
7
haven't learned too much about pointers and references (my books suck), but
I'd like to show you how to sort them if their truly seperated by spaces,
you don't need a fancy sort routine. I saw your other code, and it was too
fancy for such a simple operation. You should always post your code first.
#!/usr/bin/perl
$file = 'nums.txt';
open (FILE, $file) or die "Error: $!";
#flock it
my (@array3, @array2, @array1, $tmp);
@array1 = <FILE>;
close (FILE);
chomp (@array1);
foreach (@array1)
{
@array2 = split (/ /);
@array2 = sort (@array2);
push (@array3, @array2);
}
print @array3;
on a side note- what does this do??
#!/usr/bin/perl
$file = 'nums.txt';
open (FILE, $file) or die "Error: $!";
#flock it
my (@array3, @array2, @array1, $tmp);
@array1 = <FILE>;
close (FILE);
chomp (@array1);
foreach (@array1)
{
@array2 = split (/ /);
@array2 = sort (@array2);
push (@array3, [@array2]);
}
print @array3;
The King of Pots and Pans said:On disk I have a 2d table of numbers. Something like this:
9 8 6
4 5 6
I read it in so that I have a list of references to lists. In other
words, a list of the rows.
I want to first sort by column 2, then column 3. When I sort by column
2 I get:
4 5 6
9 8 6
As expected because 5 < 8. When I sort by column 3 I get:
9 8 6
4 5 6
This is unexpected. Since 6 = 6, I don't want it to perform the
sort. See how it was already sorted by column 2 when column 3 elements
were equal, but now column 2 is unsorted again.
haven't learned too much about pointers and references (my books suck), but
I'd like to show you how to sort them if their truly seperated by spaces,
you don't need a fancy sort routine. I saw your other code, and it was too
fancy for such a simple operation. You should always post your code first.
#!/usr/bin/perl
$file = 'nums.txt';
open (FILE, $file) or die "Error: $!";
#flock it
my (@array3, @array2, @array1, $tmp);
@array1 = <FILE>;
close (FILE);
chomp (@array1);
foreach (@array1)
{
@array2 = split (/ /);
@array2 = sort (@array2);
push (@array3, @array2);
}
print @array3;
on a side note- what does this do??
#!/usr/bin/perl
$file = 'nums.txt';
open (FILE, $file) or die "Error: $!";
#flock it
my (@array3, @array2, @array1, $tmp);
@array1 = <FILE>;
close (FILE);
chomp (@array1);
foreach (@array1)
{
@array2 = split (/ /);
@array2 = sort (@array2);
push (@array3, [@array2]);
}
print @array3;