On Mon, May 06, 2002 at 12:04:14PM -0400, Jason Frisvold wrote: > Here's another simple question.... I have an array of arrays and I want > to use a foreach to do something with each entry... currently I do this > : > > foreach my $item (@myarray) { > my ($item1, $item2) = @$item; > <do stuff here> > } > > Is there a way to combine the first 2 lines? Is it any faster and less > memory intensive? (granted it's not much now, but hey, I like > optimizing things to death...) > > Something along the lines of : > > foreach my ($item1, $item2) (@myarray) { > <do stuff> > }
Now, You are a very nasty person :-) Nope, at least by my knowledge that's not possible, but advocating to find the balance between readability and shortness you're left with a. accessing $item->[0], $item->[1] for very short loops without repetitive use if $item->[nn] b. using what you already do my ($item1, $item2) = @$item but - ignoring the fact that you probably just normalized your problem - you should use more specific names like my ($name, $id) = @user_info; for longer functions Since you're thinking about that way of shortening your code, I guess you're a more or less experienced programmer that is used to - and not afraid of - using the language's idioms. So consider above reply as a guide for the *real* beginners and not necessary for you. :-) -- If we fail, we will lose the war. Michael Lamertz | +49 221 445420 / +49 171 6900 310 Nordstr. 49 | [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany | http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]