perl sort array by field

Hi Everyone,

Any simple code can simplify the code below, please advice. Thanks

[root@]# cat 2.pl
#!/usr/bin/perl
use warnings;
use strict;

my @aaaaa = <DATA>;

        my @uids;
        foreach (@aaaaa) {
                my @ccccc = split (",", $_);
                push @uids, $ccccc[2];
        }

        sub by_uids {
                $uids[$a] <=> $uids[$b];
        }
        print @aaaaa[sort (by_uids (0..$#aaaaa))];

__DATA__
1,test,34
1,test2,65
2,test,35,
1,test3,34
2,test,34

[root@]# ./2.pl
1,test,34
1,test3,34
2,test,34
2,test,35,
1,test2,65
[root@]#

Assuming that you need it sorted numerically by the 3rd field (since you didn't say what exactly you need)

$ cat bla.pl
#!/usr/bin/perl
use warnings;
use strict;

print sort { my @a = split /,/, $a; my @b = split /,/, $b; $a[2] <=> $b[2]; }
  <DATA>;

__DATA__
1,test,34
1,test2,65
2,test,35,
1,test3,34
2,test,34
$ perl bla.pl
1,test,34
1,test3,34
2,test,34
2,test,35,
1,test2,65

#!/usr/bin/perl
use warnings;
use strict;

print sort {(split /,/, $a)[2] <=> (split /,/, $b)[2] } (<DATA>);


__DATA__
1,test,34
1,test2,65
2,test,35,
1,test3,34
2,test,34

cat:$perl ~/2.pl
1,test,34
1,test3,34
2,test,34
2,test,35,
1,test2,65

Thanks :b: