Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954933]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2018-02-23 01:26 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (300 votes). Check out past polls.