http://qs321.pair.com?node_id=385668


in reply to Re: no uninitialized warnings
in thread no uninitialized warnings

Danger, Will Robinson. Danger!

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

Replies are listed 'Best First'.
Re^3: no uninitialized warnings
by bronto (Priest) on Aug 25, 2004 at 16:14 UTC

    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)]);

        Or non-destructively and unambiguously:

        print join " ", map { defined() ? "'\Q$_\E'" : 'undef' } $var1, $var2, + $var3;

        Makeshifts last the longest.