Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2016-08-27 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (380 votes). Check out past polls.