Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to name an @ARRAY using a @VARIABLE

Status
Not open for further replies.

DJpennywhistle

Programmer
Jun 1, 2000
32
0
0
US
Visit site
I want to make an array every time I have a list of data separated by commas. So I use,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;if($value2=~/,/)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$number_of_arrays++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@array = split(/,/, $value2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br><br>The thing is this could happen a few times in my bigger loop so I was trying to name the @array using the $number_of_arrays. Something like <br><br>&nbsp;@array_\$number_of_arrays = split(/,/, $value2);<br><br>But perl doesn't seem to like this - any ideas?<br><br>Thanks<br><br> <p>Gordon Bell<br><a href=mailto:gordon.bell@xilinx.com>gordon.bell@xilinx.com</a><br><a href= > </a><br>
 
Just create a distinct name from each new array, stuff that string in a var, and use the var as your array name.&nbsp;&nbsp;You are so close.... just use the number of the array as the array name.<br><br><FONT FACE=monospace>while (something happens)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;if($value2=~/,/)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$number_of_arrays++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@$number_of_arrays = split(/,/, $value2); <font color=red># you get a new array name each time through</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}</font><br><br>It helps me keep my arrays organized if I name them something meaningful, so you might.....<br><FONT FACE=monospace>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$number_of_arrays++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array_name = 'thisArray'.$number_of_arrays;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@$array_name = split(/,/, $value2);</font><br><br>'hope this helps <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top