Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Winamp random m3u

by OzzyOsbourne (Chaplain)
on Mar 08, 2002 at 15:23 UTC ( #150340=sourcecode: print w/replies, xml ) Need Help??
Category: Audio Related Programs
Author/Contact Info OzzyOsbourne
Description: Creates a random playlist of the number of songs that you input. Edit a the $dir1 and $out vars.
# Generates a Random playlist of the length you specify...

use strict;
use File::Find;
my ($dir1, $input, @array);
&prep;
find(\&wanted, $dir1);
&outout;

#----------Sub Routines below this line---------------

sub prep {
    print "Enter the number of songs:";
    chomp ($input=<STDIN>);
    $dir1="//server/mp3share/";
}

sub wanted {
    if (/mp3$/){
        push @array, "$File::Find::name\n";
    }
    print'.';
}

sub outout{
    my $out="$dir1/upload/randlist.m3u";
    open OUT, ">$out" or die "Cannot open $out for write :$!";
    for (1..$input){
        
        my $number=int(rand $#array);
        my $result=splice @array, $number,1;
        $result=~s/\//\\/g;    
        print OUT "$result";
    }
    close $out;
}
Replies are listed 'Best First'.
Re: Winamp random m3u
by thraxil (Prior) on Mar 08, 2002 at 20:31 UTC

    first of all, i'd avoid using global variables (yeah, it's only a small script, but it should be habit).

    second, you can rewrite the:

    $result=~s/\//\\/g;

    as:

    $result =~ s{/}{\\}g;

    to eliminate LTS.

    anders pearson

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://150340]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2017-04-28 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (517 votes). Check out past polls.