Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Tidying up some dereferencing code

by uwevoelker (Pilgrim)
on Aug 13, 2002 at 14:15 UTC ( [id://189797]=note: print w/replies, xml ) Need Help??


in reply to Tidying up some dereferencing code

foreach (@{$self->{_words}}) { foreach my $curr (@{$_->pass_matches}) { # ... } }
Better use foreach instead of for, when you iterate over an array.

Replies are listed 'Best First'.
(jeffa) 2Re: Tidying up some dereferencing code
by jeffa (Bishop) on Aug 13, 2002 at 16:32 UTC

    "Better use foreach instead of for, when you iterate over an array."

    Why, they do the exact same thing:
    print $_ for qw(foo bar baz); print $_ foreach qw(foo bar baz); $ perl -MO=Deparse foo.pl foreach $_ ('foo', 'bar', 'baz') { print $_; } foreach $_ ('foo', 'bar', 'baz') { print $_; } foo.pl syntax OK
    I will admit that i tend to use foreach when i iterate over a 'collection', but never hardly ever (never say never...) when iterating over arrays. As a matter of fact, i have really started to favor for over foreach because foreach is just too wordy. But, consitency is alway king. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://189797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found