develooper Front page | perl.beginners | Postings from July 2003

Re: for/foreach question

Thread Previous | Thread Next
From:
Jeff 'japhy' Pinyan
Date:
July 24, 2003 10:02
Subject:
Re: for/foreach question
Message ID:
Pine.LNX.4.44.0307241300520.11124-100000@perlmonk.org
On Jul 24, Peter Fleck said:

>for $arrayref (@datedbi) {
>    #do stuff
>}
>
>It didn't look right and sure enough, it should be 'foreach'.
>
>But it worked fine and that's my question - why is this working?

In Perl, 'for' and 'foreach' are the EXACT SAME THING.

  for $x (@list) ...
  foreach $x (@list) ...

  for ($x = 0; $x < 10; $x++) ...
  foreach ($x = 0; $x <= 10; $x++) ...

Each pair is identical.  I never use "foreach"... it's four extra
characters, and I think "for" works in both instances just fine.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About