You can't avoid having a variable as global if it is used in global scope. The first use does not necessarily imply the scope of a variable, as you found out.
I would possibly rewrite your code as follows:
sub get_response { my ($res) = @_; die "Required argument missing" unless $res; if ($res =~ /Hello/i) { return "Hello to you.\n"; } else { return "Huh?\n"; }; }; print get_response(@ARGV);
In reply to Re: Best way to pass variables?
by Corion
in thread Best way to pass variables?
by Elijah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |