Learn about Linux
Download Linux
Get Linux help
Get special offers on:
Linux Application Dev Programming Software
Email:
#
Return to Command line Perl for sysadmins
© Copyright 1999-2008 - SourceForge, Inc., All Rights Reserved About Linux.com - Privacy Statement - Terms of Use - Advertise - Trademark - Ask Linux Questions - Write for Us - RSS Feed ThinkGeek - Slashdot - SourceForge.net - freshmeat - Surveys - Jobs
Shuffle
Posted by: Anonymous Coward on March 23, 2006 06:31 AMPick a random file (e.g. MP3)
ls | perl -e '@a=<>;print $a[rand(@a)]'
and:
Shuffle the contents of a file
cat foo | perl -e '@a=<>;while(@a){print splice(@a,rand(@a),1)}'
The latter is awash with Perl Wizardry (using an array in scalar context, the splice() function, etc.) but it's simplistic in its brevity.
#