Most efficient way of checking for a return from a function call in Perl

Posted by Gaurav Dadhania on Stack Overflow See other posts from Stack Overflow or by Gaurav Dadhania
Published on 2011-01-11T02:55:26Z Indexed on 2011/01/11 5:53 UTC
Read the original article Hit count: 234

Filed under:
|

I want to add the return value from the function call to an array iff something is returned (not by default, i.e. if I have a return statement in the subroutine.)

so I'm using unshift @{$errors}, "HashValidator::$vfunction($hashref)"; but this actually adds the string of the function call to the array. I also tried unshift @{$errors}, $temp if defined my $temp = "HashValidator::$vfunction($hashref)"; with the same result. What would a perl one-liner look like that does this efficiently (I know I can do the ugly, multi-line check but I want to learn).

Thanks,

© Stack Overflow or respective owner

Related posts about perl

Related posts about pass-by-reference