
Kanji
User
Aug 14, 2000, 1:57 PM
Post #4 of 4
(221 views)
|
|
Re: Changing the name of an array
[In reply to]
|
Can't Post
|
|
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> push @{ "special_$count" }, $_;</pre><HR></BLOCKQUOTE> ...will create @special_0, @special_1, etc. IMHO, you'd be better off going with an array of arrays... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> my @special; my $count = 0; foreach my $cat (@cat) { $count++ if ($category =~ /^01/); push @{ $special[$count] }, $_; }</pre><HR></BLOCKQUOTE> ...which is functionally equivalent to creating the following... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> @special = ( [ 1, 2, 3 ], # @{ $special[0] } [ 3, 4, 5 ], # @{ $special[1] } [ 6, 7, 8 ], # @{ $special[2] } );</pre><HR></BLOCKQUOTE> Then you could do print @{ $special[2] }; and get 6, 7, & 8, while print $special[0][2]; would get 3.
|