Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Populating Arrays of Arrays

by Tanktalus (Canon)
on Mar 03, 2005 at 19:11 UTC ( [id://436335]=note: print w/replies, xml ) Need Help??


in reply to Populating Arrays of Arrays

You have:

#this line is problematic @$scalarclose[$count]=map {$_}, @ctagarray;
I'm zeroing in on this. What you probably want is:
@$scalarclose[$count]=[map {$_}, @ctagarray];
An array can only hold a scalar, even if that scalar is actually a ref to something else. In this case, I've made the scalar into a ref to an anonymous array.

Note that you have way too many declarations up front. Try moving the "my" closer to where each variable is first used. This is Perl, not Pascal. Thanks.

Replies are listed 'Best First'.
Re^2: Populating Arrays of Arrays
by husker (Chaplain) on Mar 03, 2005 at 19:59 UTC
    Note that you have way too many declarations up front. Try moving the "my" closer to where each variable is first used. This is Perl, not Pascal. Thanks.

    Is that really a big deal? I declare the same way (although I will group declarations together).

      Is that really a big deal?

      It's indicative of a weak understanding of lexical scope. It's a symptom of a problem, not a problem in and of itself. Putting a huge block of my declarations at the top of the file is not a whole lot better than using package variables for everything. About the only benefit you get from strict is checking for typos.

      I prefer to scope variables as tightly as possible. That means, at the latest possible time and smallest possible block for the code to still work. Then, not only do I get protection against typos in variable names, I also get protection against inadvertant action-at-a-distance.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-09-11 15:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (13 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.