ethrbunny has asked for the wisdom of the Perl Monks concerning the following question:

I have a series of jobs that run on remote hosts via SSH. I've been redirecting the STDERR and STDOUT to see whether or not the process succeeded on the remote host(s). This works great - mostly. I have one process that gives me scripting errors even though it completes successfully.

Sample message: Use of uninitialized value in substitution (s///) at C:/Perl/site/lib/PPM/Installer.pm line 285.

As I said - the script completes successfully but Im getting an 'unsuccessful' result. Is there some way to filter out these 'non-breaking' errors from the 'real' ones?
  • Comment on Separating 'real' errors from ..err.. 'unreal'?

Replies are listed 'Best First'.
Re: Separating 'real' errors from ..err.. 'unreal'?
by archfool (Monk) on Jul 13, 2007 at 14:30 UTC
    You could wrap your call to PPM::Installer in a block and do the following:
    { no warnings 'uninitialized'; PPM::Installer->whatever(...); }
      I was also trying to selectively pipe STDERR to /dev/null but Im getting a "The system cannot find the path specified." error from calling a command that includes "2>/dev/null" in it. I tried with both back-ticks and 'system'.

      I'll give your idea a try. Thanks.

      Addendum: worked great! Thanks **2
        To redirect STDERR to the null device on windows you need to do it as 2>nul.

        Cheers,
        Rob
Re: Separating 'real' errors from ..err.. 'unreal'?
by citromatik (Curate) on Jul 13, 2007 at 14:05 UTC

    You are getting those warnings (not errors) because you are trying to use uninitialized variables. To avoid them, check if the variable is defined before using it, for example with:

    $var =~ s/foo/bar/ if (defined $var);

    Hope this helps

    citromatik

      This is coming from somewhere deep inside PPM. That's what has me puzzled. Im trying to trace back to where I might be calling this.
Re: Separating 'real' errors from ..err.. 'unreal'?
by rpanman (Scribe) on Jul 13, 2007 at 14:04 UTC
    Normally this error occurs when the scalar you are performing the subsitution on has no content. So for example:
    my $tech; $tech =~ s/a/b/;
    ... will result in the error. To get around it you can do the following:
    my $tech; $tech =~ s/a/b/ if defined $tech;
    I hope that helps.