[NTLUG:Discuss] Perl help

Michael Barnes barnmichael at gmail.com
Thu Feb 7 15:56:03 CST 2008


I knew it was something simple.

Thanks so much for your help.

Michael

On Feb 7, 2008 1:46 PM, Stuart Johnston <saj at thecommune.net> wrote:
> In this case you would want a 'return'.  I changed your sub calls around
> a little too.  If you were not in a sub, you would want to use 'next'.
>
>
> sub nextcut {
>      my $path = '/path/to/files/';
>      for $n (31000 .. 31500) {
>          if (! -e "$path/$n.wav" ) {
>                print "$n.wav\n";
>                return $n;
>          }
>      }
> }
>
>
>
> if ($WDAY eq 'Mon') {
>            print "Today is Monday. \n";
>           $cut = nextcut();
>            $HR1 = "/path/to/files/Monday-truth1.wav";
>            $NEWHR1 = "/path/to/files/$cut$show$TODAY-hr1_DIST.wav";
>            copy($HR1,$NEWHR1);
>           $cut = nextcut();
>            $HR2 = "/path/to/files/Monday-truth2.wav";
>            $NEWHR2 = "/path/to/files/$cut$show$TODAY-hr2_DIST.wav";
>            copy($HR2,$NEWHR2);
>
>
>
>
>
>
> Michael Barnes wrote:
> > 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
> >



More information about the Discuss mailing list