? operator : Conditional Operators « Language Basics « Perl






? operator

  

test ? execute_if_true : execute_if_false;

#!/usr/bin/perl -w

@ar = get_value();

print "Wanted array.  Got back: @ar\n";

$v = get_value();

print "Wanted scalar. Got back: $v\n";

sub get_value {
    my(@array) = (1, 2, 3);
    my($val)   = 55;
    
    return wantarray ? @array : $val;
}

   
    
  








Related examples in the same category

1.Conditional Operator: (condition) ? statement_if_true : statement_if_false;
2.Conditional Operators and print statement