in reply to Variable Declaration

Please use code tags. I think you want (not valid perl):

my $var2; if <cond1> { $var2 = a; } else { $var2 = y; }

-derby

Replies are listed 'Best First'.
Re^2: Variable Declaration
by ikegami (Patriarch) on Aug 31, 2007 at 15:09 UTC

    The following would also work:

    my $var2 = <cond1> ? a : y;

    But be careful. Even slight complexity in its arguments can make it hard to read.

      A third option is
      my $var2 = do { if ( <cond1> ) { a; } else { y; } };

      All three constructs are more-or-less interchangable and which one you use should be decided based on which is most readable in any particular instance.