Well, one problem you're having is context confusion:
If you want $option to get the _value_, instead of the number of elements in the array, you'll need to either learn about wantarray so your sub knows how it's called, or return a scalar, or do list assignment (which looks like ($option)=process_input($option). Perl is examining @data in a scalar context in your return statement, which gives the number of elements it contains, rather than its contents, because the sub was called as the rvalue of a scalar assignment.perl -e 'sub foo {@a=(1,2,4);return @a}; $bar=foo(); print "bar is $bar\n";' bar is 3
In reply to Re^5: Returning and passing data to and from subroutines
by ssandv
in thread Returning and passing data to and from subroutines
by vendion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |