in reply to stderr output

Redirection in NT is accomplished much like in Unix.
Redirecting STDOUT is done with > or 1>, redirecting STDERR
with 2>.

For example

n:\>ls c:\foo ls: c:/foo: Not a directory n:\>ls c:\foo 2> c:\tmp\error.txt n:\>more c:\tmp\error.txt ls: c:/foo: Not a directory n:\>
However, in this precise instance, I think you would be
better off fixing the source of the error, in this
case, exiting a subroutine with next. You should use
return to exit a subroutine, not next, which is use for
going to the next item in a loop.

Regards,
Helgi Briem

Replies are listed 'Best First'.
Re: Re: stderr output
by Anonymous Monk on Sep 09, 2002 at 18:16 UTC
    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"; }
      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.

      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!