You don't show the relevant code, but my guess is that the issue is scalar context vs. list context.
Most likely you have something like
sub nonblank { return grep { /\S/ } @_ } print nonblank('foo'); # list context through print() print $_ for nonblank('foo'); # explicit list context my $temp= nonblank('foo'); # scalar context print $temp; # still scalar ( $temp)= nonblank('foo'); # list context, discarding all but the firs +t element print $temp; # First element of that list $temp= (nonblank('foo'))[0]; # Scalar context in assignment, but we + only take the first element explicitly print $temp;
... and grep returns a list, even if you are really, really certain that there will only ever be one matched element. And that list, when evaluated in scalar context turns into the number of elements. Which is 1.
In reply to Re: Return Value from sub
by Corion
in thread Return Value from sub
by Dr Manhattan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |