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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: concatenate scalar with array name by Eily
in thread concatenate scalar with array name by iThunder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-19 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found