@array to %hash

2002-11-20 Thread Fogle Cpl Shawn B
I have 2 arrays I would like to make into a (one) hash.

One array for keys.
One array for values.

I'm sure this may be an easy thing, but my lack of imagination is killing me
(and I need something a little more comprehensive than Beginners Perl)

tia
shawn 

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




File::Find cache?

2002-11-11 Thread Fogle Cpl Shawn B
Does File::Find cache itself to memory even after the script has been
completed? I've put a script together that is going to find ~1785 files in
30 directories..

The First time I try my script after computer's turned on...

real0m14.972s
user0m0.410s
sys 0m0.270s

and the second time ~30 minutes later

real0m0.482s
user0m0.420s
sys 0m0.060s

I don't concider this too much a problem, but this has to be in memory
(right?), will it eventually clear it?

Thanks,
shawn


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




Using non-standard characters...

2002-10-23 Thread Fogle Cpl Shawn B
Sorry about the incorrect syntax's, I'll put a little more time into
preparing my question before I send out another one. The problem is now
fixed though.

Thanks for your help,

shawn

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




RE: Using non-standard characters...

2002-10-22 Thread Fogle Cpl Shawn B
Sorry, the file gets cut off at the '.

i.e. if a scalar variable is
/mnt/disk/sound/high_quality/how_now_brown_cow_ain't_happenin.flac
it will cut off at the ' in ain't. now my thought was something like this

here's something to be a little more descriptive:

my $i = /mnt/disk/sound/high_quality/how_now_brown_cow_ain't_happenin.flac;

if ( /[']/ ) {
link /tmp/tmp_music_file $i;
system flac qq(flac -c -d /tmp/tmp_music_file | rawplay);
}
This is a very crude example (the syntax is probably incorrect also but
hopefully you can tell what I'm trying to accomplish) of something that
would be implemented in my program.
Now this might work (though I haven't had time to get it to work yet). I
just know there's got to be a better way than this workaround. 

This was the way I had it before:

my $i = /mnt/disk/sound/high_quality/how_now_brown_cow_ain\'t_happening.flac
system qq(flac -c -d $i | rawplay);

And it would output something like
flac can't play "/mnt/disk/sound/high_quality/how_now_brown_cow_ain'".

which basically skips the file, and makes my program useless for these files
unless I (or the user) renames their files. And yes I know ain't ain't a
word =)

thanks in advance
shawn fogle

p.s. maybe a regexp to substitute would work...something like s/[']/[\']/g
but it doesn't seem to work..anyone? 

-Original Message-
From: Jenda Krynicky [mailto:Jenda@;Krynicky.cz]
Sent: Monday, October 21, 2002 11:50 PM
To: [EMAIL PROTECTED]
Subject: Re: Using non-standard characters...


From:   Fogle Cpl Shawn B <[EMAIL PROTECTED]>

> I'm having a little problem with some of my filenames that have ' in
> them (I would enclose it in quotes but that would probably confuse
> things).  And it never makes it beyond that point in the filename when
> running the script. I have thought of makeing a link to a temp file
> with a better name (something simple like /tmp/npntemp) using regexps.
> But, maybe I'm not thinking of all the possibilities here, but I know
> using the ' character is not a problem on the shell, as I can just
> type the command on the shell and it works fine. 

You forgot to tell us WHAT problem do you have with those files.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Using non-standard characters...

2002-10-21 Thread Fogle Cpl Shawn B
I'm having a little problem with some of my filenames that have ' in them (I
would enclose it in quotes but that would probably confuse things).  And it
never makes it beyond that point in the filename when running the script. I
have thought of makeing a link to a temp file with a better name (something
simple like /tmp/npntemp) using regexps. But, maybe I'm not thinking of all
the possibilities here, but I know using the ' character is not a problem on
the shell, as I can just type the command on the shell and it works fine. 

Any suggestions?
As usual I'd like to thank everyone for their help,
shawn

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




Couple of qustions...

2002-10-16 Thread Fogle Cpl Shawn B

How would I go about going to a previous line? 

I would also like to do several regexp's against a scalar value...something
like this (hopefully you know a way for me to make this shorter!)

$next_music_file =~ s/[.]/ /;
$next_music_file =~ s/^[0]//;
$next_music_file =~ s/.flac//;
$next_music_file =~ s/[_]/ /g;

Thanks for any help.

shawn

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




Segfaults

2002-10-12 Thread Fogle Cpl Shawn B

When I make perl segfault due to something stupid I did should I just ignore
it or report it as a bug? (yes I can reproduce it)

thanks
shawn

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




Perl regexp tutorial?

2002-10-08 Thread Fogle Cpl Shawn B

Can anyone point me to a regexp tutorial (or manpage for that matter). I
can't seem to find good information that's too indepth on the subject (and
some of you guys look like regexp wizards).

thanks,
shawn

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




RE: Wanna Help?

2002-10-07 Thread Fogle Cpl Shawn B

sub random { my $music_phile = $_[rand @_]; }
# The @$ is used to get to the array from the array reference that is
# passed into the sub. I will explain the code as given in
# perldoc -q shuffle

 sub fisher_yates_shuffle {
 my $deck = shift;  # $deck is a reference to an array
 my $i = @$deck; # @$deck gets to the array from the reference
 # In scalar context this will give the number
 # of elements in the array.
 while ($i--) {
 my $j = int rand ($i+1);
 # perldoc -f rand, rand returns a value greater than or equal to 0
 # and less than it's argument. In this case, greater than or equal
to 0
 # and less than the current index + 1. This makes sure that the
indices
 # that have been shuffled do not get shuffled again

 @$deck[$i,$j] = @$deck[$j,$i];
 # This is how you swap array elements in perl. Swap the value of
the
 # current index with the one returned from rand.
 # This style (@$deck[$i,$j]) is called an array slice
 }
}

# You also have a choice to use the shuffle function from List::Util.
# You can get this module from 
# http://search.cpan.org/author/GBARR/Scalar-List-Utils-1.0701/
# You can shuffle your array by including this function and calling
# it as fisher_yates_shuffle (\@music_list)

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;

###
# Begin Body of the Script
###

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

###
# Begin Subroutines
###

# subroutine terminate: built for expandability :)
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/$_") } 
}

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

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; };
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];
}
}

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




Wanna help?

2002-10-07 Thread Fogle Cpl Shawn B

I created a simple little program to play my flac files (see
http://flac.sf.net) randomly, this is my first program of any time to take
it easy on me (and I know I'm not too stylish, and I love one liners). The
problem is that when I play the files, I want it to go through the whole
array @music_list before it plays the same song over again. I have studied
the  fisher_yates_shuffle but I can't seem to implement it to save my life.
It would help quite a bit if I understood what "@$" is and how to
effectively use it. I don't see it in the beginners manual (and haven't
searched the perldocs yet). Please feel free to diff me any improvements you
have, I'd love to see what improvements can be made (be it known I am
working on the short getopts).

Thanks in advance
shawn

--
Sorry about the email from Outlook, I'm MidEast and have not much
another choice ;)

 <> 



flacme
Description: Binary data

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


Quit with keystroke?

2002-09-06 Thread Fogle Cpl Shawn B

I'm writing my first perl script with the llama (the beginner o'riley book)
but the one thing I need to make a complete program that I don't see in the
book or the perl faqs (although I'd bet it's there somewhere) is a
acceptable way to cause the script to terminate. I have been having to goto
another VC and kill the perl script. It would be nice for me to be able to
press "Q" but that, to my little bit of knowledge of perl, would require a
 that was somewhat passive. Any suggestions? (I won't be asking many
more newbie questions, as this is the only one that has seemed to stump me
for the last week two).

tia
shawn

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