in reply to a HASH ref while "strict refs" ERROR
In the second, showArray(@arr) appears before the prototype for showArray is known, so the prototype is ignored. In the first, showArray(@arr) becomes showArray(\@arr), but there's no change in the second snippet. Yet another reason to avoid prototypes. The following is a solution that's no less efficient and doesn't exhibit the problem regardless of the order in which the functions are defined:
#!/usr/bin/perl -w use strict; sub higherLevel { my(@arr) = @{(shift)}; showArray(\@arr); } sub showArray { my(@arr) = @{(shift)}; my($temp); foreach $temp (@arr) { print "$temp\n"; } } my(@arr) = ("one","two","three"); higherLevel(\@arr);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: a HASH ref while "strict refs" ERROR
by Roy Johnson (Monsignor) on May 04, 2005 at 17:57 UTC | |
by ikegami (Patriarch) on May 04, 2005 at 19:27 UTC |