#!usr/bin/perl # randomly shuffles files in its directory by number. # i made this to randomize play in my mp3 player. # run with -x to unsort srand; @new = (); @b = <*>; @old = 01 .. (@b-1); foreach $b (@b) { unless($b eq "shuffle.pl") { print "$b\n"; } } print "\n"; for( @old ){ my $r = rand @new+1; push(@new,$new[$r]); $new[$r] = $_; } foreach $b (@b) { $_ = $b; $_ =~ s/^[0-9]*_//; rename($b, $_); } @b = <*>; $i=0; unless($ARGV[0] eq "-x") { foreach $b (@b) { unless($b eq "shuffle.pl") { rename($b, "$new[$i]_$b"); $i++; } } } @c = <*>; foreach $c (@c) { unless($c eq "shuffle.pl") { print "$c\n"; } }