Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: undefined value in array reference

by davido (Cardinal)
on Mar 31, 2011 at 18:53 UTC ( [id://896697]=note: print w/replies, xml ) Need Help??


in reply to undefined value in array reference

In your writeup you mention @aod, and in the script show us @aob. @aob is never declared within the sub popnum3. A first step toward keeping things from breaking easily is to make sure that all the variables used in a sub are passed to it explicitly, rather than absorbing from outer scopes. Perhaps you could pass @aob from an outer scope like this:

sub popnum3 { my @inner_aob = @{ shift @_ }; # reconstitute a reference

or

sub popnum3 { my $aobref = shift @_; # Just pass and use the ref instead.

As soon as subs start absorbing values rather than having values passed to them, they become fragile, and it makes it all the harder to track down the effects of small changes elsewhere in the code. Keeping scopes narrow and passing values reduces 'errors at a distance.' This isn't actually the specific error you're describing, but it as advice that will make your code easier to deal with.


Dave

Replies are listed 'Best First'.
Re^2: undefined value in array reference
by Dandello (Monk) on Mar 31, 2011 at 19:05 UTC

    @aod was a typo. Sorry

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found