Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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";
Output:
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.

CountZero

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2014-07-11 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls