in reply to Re: stderr output
in thread stderr output

Thanks it works. Questions: What does "return" do different compared to "next" in a subroutine? Also does the way I did my return part look okay? The error output (Exiting subroutine via next at C:\Perl\bin\myscript.pl line 188.) never comes up in my text file (bas.txt) for some unknown reason?
if ($data =~ /patternmatch/i) { open FILY, ">bas2.txt"; print FILY "Skip $data\n"; return ">bas2.txt"; }

Replies are listed 'Best First'.
Re: Re: Re: stderr output
by greenFox (Vicar) on Sep 10, 2002 at 05:41 UTC
    next is for loop control while return is for returning from a subroutine. Witness the different behaviour in this (demonstration only) code:
    mysub(5); sub mysub { my $val = shift || 8; print "next demo: \n"; for (1..10){ next if $_ == $val; print $_, "\n"; } print "\nreturn demo: \n"; for (1..10){ return if $_ == $val; print $_, "\n"; } }

    --
    Until you've lost your reputation, you never realize what a burden it was or what freedom really is. -Margaret Mitchell

      Thanks for the detailed explanation! Now I understand.
Re: Re: Re: stderr output
by BrowserUk (Patriarch) on Sep 10, 2002 at 00:08 UTC

    if ($data =~ /patternmatch/i) { open FILY, ">bas2.txt"; print FILY "Skip $data\n"; return ">bas2.txt"; }

    Just so that we don't steer you wrong, could you tell us what you think this piece of code is doing? Just a plain english description will do.

    It might also be advantageous to you to post a little more of your code, including the rest of this subroutine, and the part where it is called.


    Well It's better than the Abottoire, but Yorkshire!