in reply to Sharing a variable between subroutines
I rewrote your code with some adjustments:
The first thing to notice is that $array is a reference:use strict; &specific(); sub callme { my ($array,$i) = @_; $array->[$i] = "printme-"; # note the arrow operator } sub specific { my $array = [(0..5)]; &callme($array,$_) for (0..$#$array); print join("\n", @$array), "\n"; }
Also, using subroutine prototypes is not recommended. Last note, why iterate through an array one element at a time and pass the index and the array off to another subroutine? Wouldn't simply passing the array reference to a sub that iterates it be better?# this is not really correct: my @array = [0,1,2,3,4,5]; # use this: my $array = [(0,1,2,3,4,5)]; # or this: my @array = (0,1,2,3,4,5);
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Sharing a variable between subroutines
by Anonymous Monk on Dec 28, 2001 at 21:47 UTC |