Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Does Scope of Referenced Array Matter?

by CountZero (Bishop)
on Feb 19, 2012 at 22:47 UTC ( #954933=note: print w/ replies, xml ) Need Help??

in reply to Does Scope of Referenced Array Matter?

Try this:

sub a_sub { my @array = qw /a b c d e f g/; $ref = \@array; } a_sub(); print "$ref - @$ref - @array";
ARRAY(0x9dbb04) - a b c d e f g - 
The @array does not evaporate, although it can no longer be reached outside of the scope of its enclosing sub by using its lexical name. Actually the @array in the print statement has nothing to do with the @array in the sub.


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Comment on Re: Does Scope of Referenced Array Matter?
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954933]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-11-26 19:10 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (706 votes), past polls