Fogle Cpl Shawn B wrote:
> 
> Jesus! Thanks! Especially with the newline chomp thing. That was pretty
> retarded but I would have never noticed. ;)
> 
> I really didn't need a count function there at all (as I learned from
> searching the web today that $flac_count = $#music_list). I keep trying to
> implement the fisher_yates_shuffle and I keep getting the error
> 
> "Can't use string "/mnt/phoenix/sound/high_quality/" as an ARRAY ref while
> "strict refs" in use at projects/flacme line 101
> 
> so I take use strict out and get ...
> 
> Modification of a non-creatable array value attempted, subscript -1 at
> projects/flacme line 104
> 
> Welp, this time I'll c&p the script in here
> 
> ####Begin Script ;)
> 
> #!/usr/bin/perl
> 
> ###############################################################
> # Begin Modules
> ###############################################################
> 
> use warnings;
> use strict; # We must for stability
> use File::Find; # Needed for searching / portability
> use Getopt::Std; # For shell switches
> 
> ###############################################################
> # Begin Global Variables
> ###############################################################
> 
> my @music_list = ();
> my @root = qw "/mnt/phoenix/sound/high_quality/albums
> /mnt/phoenix/sound/high_quality/individuals";
> 
> my %opt;
> 
> my $flac = "flac -s -c -d"; #temporary until .flacme is implemented
> my $ver = "0.0.0a";
> my $flac_count = 0;
> 
> ###############################################################
> # Begin Signal Handlers
> ###############################################################
> 
> $SIG{'INT'} = \&terminate;

You have the terminate sub defined below.  Why not just define the whole
thing here?

$SIG{'INT'} = sub { exit 0 };


> ###############################################################
> # Begin Body of the Script
> ###############################################################
> 
> &usage();
> &find_flac();
> print `clear`;
> &version();
> &shuffle(@music_list);
> &play();
> &terminate();

You should call subroutines without the ampersand unless you really this
different functionality.

usage();
find_flac();
print `clear`;
version();
shuffle(@music_list);
play();
terminate();


> ###############################################################
> # Begin Subroutines
> ###############################################################
> 
> # subroutine terminate: built for expandability :)
> sub terminate { exit(0); }

Perl will inline this if you define a prototype with no arguments.

sub terminate () { exit 0 }


> # basic version information
> sub version {
>     print "\n\tflacme is copyrighted under the GNU General Public License";
>     print "\n\tfor more information on this license read http://www.gnu.org/
> ";
>     print "\n\tflacme-$ver\n\n\n";
> }
> 
> # Purely evil and ugly find code (kept to the minimum for reading purposes)
> sub find_flac { find (\&wanted, @root); }
> 
> sub wanted {
>     if ( /\.(flac)$/ ) { push (@music_list, "$File::Find::dir/$_") }
              ^    ^
You have parentheses there but you are not using them for anything.

    push @music_list, $File::Find::name if /\.flac$/;

> }
> 
> sub random { my $music_phile = $_[rand @_];
>              $flac_count = $#music_list;
>          }

I can't see where this is used at all or what you are trying to use it
for.


> sub play
> {
>     for (;;)
>     {
>         my $music_phile = shift(@music_list);
>         # $my $music_phile = &shuffle(@music_list);
>         print "$flac_count playing randomly...\n\n$music_phile";
>         system "$flac \"$music_phile\" | rawplay";
>         print `clear`;
>     }
> }
> 
> sub usage
> {
>     getopts('hv', \%opt);
>     if ($opt{v}) { &version; &terminate; &showopts; };
                               ^^^^^^^^^^^^^^^^^^^^^
terminate() exits the program so showopts() never gets called.


>     if ($opt{h}) { &showopts };
> }
> 
> sub showopts
> {
>     print "\nUSAGE: flacme [-vh]\n\n";
>     print "OPTIONS:\n\n";
>     print " -h\t\t\t\tthis help screen\n";
>     print " -v\t\t\t\tprint version\n";
>     &version;
>     &terminate;
> }
> 
> sub shuffle {
>     my $music_shuffle = shift;
>     my $i;
> 
>     for ( $i = @$music_shuffle; --$i; ) {
>         my $j = int rand ($i+1);
>         @$music_shuffle[$i,$j] = @$music_shuffle[$j,$i];
>     }
> }


It looks like you are just using subs for the sake of using subs.  I
would probably write it like this:

#!/usr/bin/perl
use warnings;
use strict; # We must for stability
use File::Find; # Needed for searching / portability
use Getopt::Std; # For shell switches

###############################################################
# Begin Global Variables
###############################################################
my @music_list;
my @root = qw(/mnt/phoenix/sound/high_quality/albums
/mnt/phoenix/sound/high_quality/individuals);
my $flac = 'flac -s -c -d'; #temporary until .flacme is implemented
my $ver = '0.0.0a';
my $usage = <<USAGE;

USAGE: flacme [-vh]

OPTIONS:

 -h\t\t\t\tthis help screen
 -v\t\t\t\tprint version
USAGE
my $version = <<VERSION;

\tflacme is copyrighted under the GNU General Public License
\tfor more information on this license read http://www.gnu.org/
\tflacme-$ver


VERSION

###############################################################
# Begin Subroutines
###############################################################
sub terminate () { exit 0 };
$SIG{'INT'} = \&terminate;

sub find_flac { find( sub { /\.flac$/ and push @music_list,
$File::Find::name }, @_ ) }

###############################################################
# Begin Body of the Script
###############################################################
my %opt;
getopts( 'hv', \%opt );
if ( exists $opt{'v'} ) {
    print $version;
    terminate;
    }
if ( exists $opt{'h'} ) {
    print $usage, $version;
    terminate;
    }

find_flac( @root );
system 'clear';
print $version;

# Fisher-Yates shuffle
my $i = @music_list;
while ( $i-- ) {
    my $j = int rand ( $i + 1 );
    @music_list[ $i, $j ] = @music_list[ $j, $i ];
    }

my $flac_count = 0;
while ( @music_list ) {
    my $music_phile = shift @music_list;
    # $my $music_phile = &shuffle(@music_list);
    print "$flac_count playing randomly...\n\n$music_phile";
    system qq($flac "$music_phile" | rawplay);
    system 'clear';
    } 

terminate;

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to