[Israel.pm] sort of tow dimensional array
Semuel Fomberg
semuelf at 012.net.il
Tue Jun 27 01:23:38 EEST 2006
Hello There.
You just need to change one line:
foreach $row(sort {$a->[0] <=> $b->[0]} @array)
and all will be well.
Semuel.
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On
Behalf
> Of rami doqa
> Sent: Monday, June 26, 2006 6:04 PM
> To: perl at perl.org.il
> Subject: [Israel.pm] sort of tow dimensional array
>
> hello . i am trying to sort the tow dimensional array
> with depending on the element [0] for each row:
> ex:
>
> my @array = ();
> $array[0] = [100,'text_0'];
> $array[1] = [109,'text_1'];
> $array[n] = [80, 'text_n'];
>
> when I do the sorting like this:
>
> foreach $row(sort {$a <=> $b} @array)
> {
> print $row->[0] . "," . $row->[1]; # i want to
> #sort by the first index which must be $row->[0] = 80
> }
>
> i noticed that the array is sorted ascending depending
> on the index of each row
>
> so i need a help how can i sort by the $array[$i][0]
> for each rows of the array.
>
> regards,
> Dakka, Rami
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.394 / Virus Database: 268.9.4/375 - Release Date:
25/06/2006
More information about the Perl
mailing list