Spotted this on a.h.b-o-u, its originally from clpm .... ----- Forwarded message from Gwyn Judd <[EMAIL PROTECTED]> ----- Newsgroups: alt.humor.best-of-usenet Organization: best of usenet humor X-FAQ-Via-WWW: http://www.faqs.org/faqs/best-of-usenet-humor/ From: Gwyn Judd <[EMAIL PROTECTED]> Subject: [comp.lang.perl.misc] NEWBIE DEMANDS HELP NOW!!!!!! Date: Tue, 27 Feb 2001 17:32:21 GMT Subject: NEWBIE DEMANDS HELP NOW!!!!!! From: [EMAIL PROTECTED] (Bernard El-Hagin) Newsgroups: comp.lang.perl.misc Hi, After frequenting this newsgroup for over 2 years I've come to know some of the regular posters here and decided that, as a service to newbies, I'd write up some typical regular poster replies to typical newbie questions. That way someone new to the group can pick the style of answer he/she prefers and look for that person in the future. DISCLAIMER! My goal in doing this is not to offend anyone. Quite the contrary, actually. __________ Typical newbie question: Subject: NEWBIE DEMANDS HELP NOW!!!!!! I'm new to PERL. I want to sort an array, but don't know how. I've spent hours searching the Web, the docs, the FAQs, the books, and under my bed, but couldn't find the answer. You must help me NOW or I'll get fired. __________ Typical answers: Randal Schwartz: Funny you should ask that. I just wrote an article about sorting for my Web Techniques column. Check it out. <url follows> __________ Tom Christiansen: You do yourself a grave disservice by calling yourself a "newbie". Maybe "beginner" or even "neophyte" would be more appropriate. __________ Abigail: That's trivial. Here's the fastest possible solution anywhere ever: my @sorted = *^&^@#&^*89(&*^@^@#^&*55238&^%&&@#^%%@*^#^@&*^@#^&#@@# %^&%&^%%&^&%^^@&^#$($)(@$&@#!&*@^#&*!^#*&!#^*&!#!#%!#^()$)@*$@#$)&@ &*(^$@#&*^@$#%^%^&%&%&^%&&(!@$^@$^@$@$(@^$&^&*!*&%!%@#*)$^@&@$%%%%! @unsorted; HTH. HAND __________ Tad McClellan: It's Perl or perl, not PERL (perldoc perlfaq1). You are expected to read the standard documentation that comes with your distribution of Perl before wasting the time of billions of people with a question you could have answered for yourself. This particular question could have been answered by simply doing: perldoc -f sort Don't forget to enable warnings and strictures even when you're not writing in Perl. It's *that* important. __________ uri guttman: where's that damn shift key!? oh, and godzilla must die! __________ Martien Verbruggen: It's not clear from your post what it is you're sorting and how you want to sort it. If it's a simple ASCII sort you want just use the builtin sort function: my @sorted = sort @unsorted; If, on the other hand, you'd like to sort the array numerically, you'll have to try something like: my @sorted = sort {$a <=> $b} @unsorted; To make that sort ascending just switch $a and $b: my @sorted = sort {$b <=> $a} @unsorted; Note that you can also ASCII sort in ascending order like so: my @sorted = sort {$b cmp $a} @unsorted; To get more information about sorting read: perldoc -f sort perldoc -q 'sort' __________ Bart Lateur: my @sorted = sort @unsorted; __________ Mark-Jason Dominus: You could change the perl source code to always sort arrays when you print them. __________ Godzilla!: You male chauvinist pig! You dare attack mighty Kira with your mule manure! I will stomp.stomp.stomp you! #!/usr/bin/perl print "Content-Type: text/plain\n\n"; print "Test case follows:\n"; print "The next line will be the test case:\n"; print "Here we go:\n"; @sorted_array = map {$a = $b} @array; print "Godzilla Rulez!\n"; __________ Cheers, Bernard -- #requires 5.6.0 perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }' -- Moderators accept or reject articles based solely on the criteria posted in the Frequently Asked Questions. Article content is the responsibility of the submitter. Submit articles to [EMAIL PROTECTED] To write to the moderators, send mail to [EMAIL PROTECTED] ----- End forwarded message ----- -- Greg McCarroll http://www.mccarroll.uklinux.net