NOYB has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl A(); B(); sub A { my @array = qw(value_1 value_2); $array_ref = \@array; } sub B { foreach my $i ( @{$array_ref} ) { print "Array Value: $i \n"; } }
Since the array is declared using the 'my' keyword, could the array reference be lost if/when the array itself falls out of scope?
I know this example script functions, but is it just happenstance?
Or will the reference prevent the array itself from vaporizing when/if it falls out of scope? Or should the array be declared without using the 'my' keyword?
Thanks,
This is me. And I wouldn't lie about a thing like that. - Paraphrased from MASH dialog.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Does Scope of Referenced Array Matter?
by Eliya (Vicar) on Feb 19, 2012 at 22:34 UTC | |
|
Re: Does Scope of Referenced Array Matter?
by CountZero (Bishop) on Feb 19, 2012 at 22:47 UTC | |
|
Re: Does Scope of Referenced Array Matter?
by tangent (Parson) on Feb 19, 2012 at 22:37 UTC | |
|
Re: Does Scope of Referenced Array Matter?
by ikegami (Patriarch) on Feb 20, 2012 at 09:23 UTC | |
|
Re: Does Scope of Referenced Array Matter?
by Anonymous Monk on Feb 19, 2012 at 23:15 UTC | |
|
Re: Does Scope of Referenced Array Matter?
by NOYB (Novice) on Feb 19, 2012 at 23:59 UTC | |
|
Re: Does Scope of Referenced Array Matter?
by repellent (Priest) on Feb 20, 2012 at 22:22 UTC |