in reply to Best way to pass variables?
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);
|
|---|