Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Winamp random m3u

by OzzyOsbourne (Chaplain)
on Mar 08, 2002 at 15:23 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://150340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found