Random Perl snippet

This one messed me up until I figured out that splitting on comma instead of comma-space gave me a leading space in the strings, which then sorted weirdly.

H:\>perl -e “print join qq/, /, sort {$a <=> $b } split /, /, qq/2, 3, 5, 10, 19, 20, 58, 64, 65, 330, 452, 721, 797, 798, 799, 978, 1036, 1037, 1045, 1061, 1128, 1129, 1232, 1290, 1471, 858, 895, 1289, 1248, 64, 1479, 1464, 59, 65, 58, 1465, 1466, 1326, 1290, 1326, 1615, 1679/”

2, 3, 5, 10, 19, 20, 58, 58, 59, 64, 64, 65, 65, 330, 452, 721, 797, 798, 799, 858, 895, 978, 1036, 1037, 1045, 1061, 1128, 1129, 1232, 1248, 1289, 1290, 1290, 1326, 1326, 1464, 1465, 1466, 1471, 1479, 1615, 1679

Posted by Garrett on June 3rd, 2008 in perl | No Comments