in reply to Re: Variable scoping when a sub calls itself??
in thread Variable scoping when a sub calls itself??

Thanks for the tips. Fixed it now. And don't worry, I always use () with & so as not to get strange behavior. Just like being able to quickly distinguish between my routines and perl's.
  • Comment on Re^2: Variable scoping when a sub calls itself??

Replies are listed 'Best First'.
Re^3: Variable scoping when a sub calls itself??
by ikegami (Patriarch) on Apr 15, 2008 at 23:17 UTC

    And don't worry, I always use () with & so as not to get strange behavior.

    & also disables prototypes.

    use strict; use warnings; sub my_splice(\@$;$@) { my ($array, $start, $length, @insert) = @_; return splice(@$array, $start, $length, @insert); } { my @array = qw( a b c ); splice(@array, 1, 1, qw( d e )); print(@array, "\n"); # adec } { my @array = qw( a b c ); my_splice(@array, 1, 1, qw( d e )); print(@array, "\n"); # adec } { my @array = qw( a b c ); &my_splice(@array, 1, 1, qw( d e )); print(@array, "\n"); # Can't use string ("a") as an ARRAY ref whil +e "strict refs" in use at !.pl line 6. }

    Now, you could argue that prototypes should be avoided, but they are used by many modules.