Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: concatenate scalar with array name

by Eily (Deacon)
on Jan 15, 2014 at 09:57 UTC ( #1070662=note: print w/ replies, xml ) Need Help??


in reply to concatenate scalar with array name

If the arrays have significant differences (they do not have the same meaning, and won't be used the same way), then it's probably better to give them significant names (like "potatoes", "tomatoes", "toes"), in which case a hash can be used (and if the arrays aren't going to be used in the same place, there's no need for having them ordered). Then you can have $hash{potatoes}[0] or $hash{toes}[-1] for exemple.

If the arrays are equivalent sets, in which case the order may be important, then an array of arrays is probably a clearer solution (and faster, but it's not a significant change if there's little data). This means that instead of $array1[0], $array2[3], $array3[9] you would write $array[1][0], $array[2][3] and $array[3][9]. The difference is that you'll have something at index 0 (it can be undef, in which case your first array will be at 1).

Since you seem to be in the second case, here is how to do it:

for my $i (0..4) { for my $j (0..4) { $array[$i][$j] = something($i,$j); } }
Of course what I said still stands, instead of @array, $i, $j and &something, you should use meaningful names.

More info in perldsc


Comment on Re: concatenate scalar with array name
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-12-19 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (90 votes), past polls