in reply to reduce line of code

This is probably what you're after.

my $cmd = $step_no || 0; # If $step_no is 0, it assigns... uh, 0 over it.

Note that if you're accepting user input, like $step_no = param("step") or something you should validate all user parameters before using them in other code. Perhaps-

my $cmd = $step_no =~ /\A\d+\z/ ? $step_no : 0;

Replies are listed 'Best First'.
Re^2: reduce line of code
by ysth (Canon) on Jul 14, 2009 at 06:36 UTC
      I guess this is what Sun751 meant. His non-working example scopes the $cmd variable to the if ... else blocks.
        OT: just add
        use strict ; use warnings ;
        to your programs, witch would have detected your scoping problem!

        LuCa