in reply to Returning Error Codes
'foo' returns array, and 'if' statement looks like
Example:if ((($r,$m) = foo($i))[0]) {
#!/usr/bin/perl use strict; my ($m, $r); foreach my $i (1 .. 2) { print "\n"; if ((($r,$m) = foo($i))[0]) { print "It worked\n"; } else { print "error: $m\n"; } } sub foo { my $num = shift; my @ret = (); if ($num == 1){ print "inside foo, good\n"; @ret = ($num,"good input number"); } else { @ret = (0,"bad input number"); } return @ret; }
|
|---|