The distinctive Perl camel is (c) O'Reilly
Perl Workshop Home Page
Home of the Bioinformatics Perl Workshop perl workshop > courses > introduction to perl (1.0.1.8) > Hashes and Sorting (.4/8) > sort (.c2)

course 1.0.1.8

Level: beginner
1.0.1.8.4
Introduction to hashes: keys, values, exist; introduction to sorting and shuffling.

legend

course code

cat.course.level.sessions.session

e.g. 1.0.1.8

categories

0 | introduction and orientation

1 | perl fundamentals

2 | shell and prompt tools

3 | web development

4 | CPAN Modules

5 | Ruby

levels

level: all all ( 0 )

level: beginner beginner ( 1 )

level: intermediate intermediate ( 2 )

level: advanced advanced ( 3 )

[ consider using for instead of foreach ]

lecture code viewer

downloads

Code
Hashes and Sorting
Hashes and Sorting
Martin Krzywinski
#!/usr/local/bin/perl $\= "\n"; use Data::Dumper; @nums = (1..20); @nums = sort { rand(3)-1 } @nums; print Dumper(\@nums); for (1..10) { push @random_numbers, rand(); } # sort the index based on array values for $i ( 0..@random_numbers-1 ) { print qq(index $i value $random_numbers[$i]); } # sort the index based on array values for $i ( sort { $random_numbers[$a] <=> $random_numbers[$b] } (0..@random_numbers-1) ) { print qq(index $i value $random_numbers[$i]); }

4 | Hashes and Sorting | 1.0.1.8.4

1.0.1.8.4.p1 | Hashes and Sorting | Martin Krzywinski | ppt
1.0.1.8.4.c1 | sequences | Martin Krzywinski | code
1.0.1.8.4.c2 | sort | Martin Krzywinski | code
1.0.1.8.4.a1 | Hashes and Sorting | Martin Krzywinski | pdf
1.0.1.8.4.a2 | Hashes and Sorting | Martin Krzywinski | pdf
1.0.1.8.4.s1 | Hashes and Sorting | Martin Krzywinski | slides