in reply to no uninitialized warnings

Why don't you just initialize them?

$_ ||= '' for $var1, $var2, $var3; print "var1=$var1 -- var2=$var2 -- var3=$var3\n";
or
print "var1=", $var1 || '', " -- var2=", $var2 || '', " -- var3=", $va +r3 || '', "\n";

Replies are listed 'Best First'.
Re^2: no uninitialized warnings
by busunsl (Vicar) on Aug 25, 2004 at 12:54 UTC
    Danger, Will Robinson. Danger!

    If $var1 has the value 0, it will be set to '', which might not be what you want.

      Mh... something like this?

      @x=(1..3) ; undef $x[1] ; $_ = defined $_? $_: '[__UNDEF__]' for @x ; print "@x" ;

      Ciao!
      --bronto


      The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
      --John M. Dlugosz

        or like this:

        $_ = '[undef]' for grep !defined, $var1, $var2, $var3; print "$var1, $var2, $var3";

        Update: I forgot that changing the values can affect program logic(as Aristotle mentioned). So, the best approach (imho) is just print with warnings or

        use Data::Dumper; print Data::Dumper->Dump([$var1, $var2, $var3], [qw(var1 var2 var3)]);
Re^2: no uninitialized warnings
by revdiablo (Prior) on Aug 25, 2004 at 17:29 UTC

    If the values might be uninitialized in the normal course of operation, and it's acceptible, then I see no problem just turning off the warning, as the OP has done. This is Perl, after all. The language should do what we want, not the other way around. :-)