Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Adding a number from scalar variable to array name

by hgolden (Pilgrim)
on Sep 08, 2006 at 18:47 UTC ( [id://572060]=note: print w/replies, xml ) Need Help??


in reply to Adding a number from scalar variable to array name

It might be easier to just use a hash. Then it would be:
foreach $num (@numbers) { $store_get{$num}=$num; }
Also, if you're just assigning one number to each of the arrays, you can just access the array element directly:
$numbers[$num-1]
is equal to $num from when you set up the array. I hope this helps.

Replies are listed 'Best First'.
Re^2: Adding a number from scalar variable to array name
by Anonymous Monk on Sep 08, 2006 at 18:51 UTC
    Well I want to store more than one variable... Reason I want to do this is for example: I want my code to create the arrays @array1, @array2, @array3... Based on the number it gets from the original array (1,2,3.... ). I want @array1 = (1,2,3), @array2 = (4,5,6), etc
      Well I want to store more than one variable...

      Why? (BTW: you are confusing variable and named variable).

      Reason I want to do this is for example: I want my code to create the arrays @array1, @array2, @array3... I want @array1 = (1,2,3), @array2 = (4,5,6), etc

      That's not a reason, it's just a restatement of the assertion that you want more than one named variable.

      Please look deep within youself and see if you can actually find a reason why you want this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://572060]
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: (3)
As of 2025-05-24 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.