[NTLUG:Discuss] Perl help
Michael Barnes
barnmichael at gmail.com
Thu Feb 7 13:41:15 CST 2008
I'm getting real closer here. Thanks for all your help. Here's what I
ended up with.
sub nextcut {
my $path = '/path/to/files/';
for $n (31000 .. 31500) {
if (! -e "$path/$n.wav" ) {
print "$n.wav\n";
$cut = $n;
}
}
}
Then in my script I have basically:
if ($WDAY eq 'Mon') {
print "Today is Monday. \n";
&nextcut();
$HR1 = "/path/to/files/Monday-truth1.wav";
$NEWHR1 = "/path/to/files/$cut$show$TODAY-hr1_DIST.wav";
copy($HR1,$NEWHR1);
&nextcut();
$HR2 = "/path/to/files/Monday-truth2.wav";
$NEWHR2 = "/path/to/files/$cut$show$TODAY-hr2_DIST.wav";
copy($HR2,$NEWHR2);
My problem is the subroutine does not stop until it gets to the end of
the list. I need something to stop the 'for' loop when it finds the
first available number and return to the script. Eric had 'exit' in
there, but that stopped the whole script. I'm sure there is something
to return to the script then start allover again when called again.
Thanks for the basic help for this noob.
Michael
On Feb 6, 2008 2:05 PM, Stuart Johnston <saj at thecommune.net> wrote:
> oops, typo:
>
> my $path = '/path/to/files';
> for $n ( 31000 .. 31500 ) { if ( ! -e "$path/$n.wav" ) ...
>
>
>
> Stuart Johnston wrote:
> > You can use Eric's solution by simply prepending the path:
> >
> > my $path = '/path/to/files';
> > for $n ( 31000 .. 31500 ) { if ( ! -e "$page/$n.wav" ) ...
> >
> >
> > Michael Barnes wrote:
> >> Thanks, Eric. This works fine run from command line in the folder
> >> containing the desired files.
> >> However, I need to include it into a script along with a bunch of
> >> other things. It will not be in the folder containing the files.
> >>
> >> I have tried
> >>
> >> $n = glob "/path/to/files/*";
> >>
> >> which, of course does not work.
> >>
> >> I guess I need to get a
> >>
> >> foreach $n (@files) {
> >>
> >> type of thing in there, but I can't get it to work.
> >>
> >> Thanks for your kind assistance.
> >>
> >> Michael
> >>
> >> On Feb 5, 2008 4:33 PM, Eric Waguespack <ewaguespack at gmail.com> wrote:
> >>> perl -e 'for $n ( 31000 .. 31500 ) { if ( ! -e "$n.wav" ) { print
> >>> "$n.wav\n"; exit }}; done'
> >>>
> >>> ./e
> >>>
> >>>
> >>> On Feb 5, 2008 4:10 PM, Michael Barnes <barnmichael at gmail.com> wrote:
> >>>> I'm looking for a quick perl script and my brain just isn't
> >>>> functioning right now.
> >>>>
> >>>> I have a folder full of audio files. Each file is a five digit
> >>>> number.wav, i.e. 12345.wav.
> >>>>
> >>>> Files are entered in this folder into particular groups of numbers, so
> >>>> there are lots of gaps.
> >>>>
> >>>> I need to search a range of these files from 31000.wav to 31500.wav
> >>>> (ignoring everything below 31000 and above 31500) and find the largest
> >>>> available file number to use. There may be files 31000.wav-31057.wav
> >>>> in use, (There would be no files 31058-31500) making 31058 the next
> >>>> available file.
> >>>>
> >>>> All I need to do is get the next number (31058 in this case) into a
> >>>> variable to be used elsewhere.
> >>>>
> >>>> I know this should be quite easy, but I sure can't get my head around
> >>>> it right now.
> >>>>
> >>>> Thanks for any help you can come up with.
> >>>>
> >>>> Michael
More information about the Discuss
mailing list