Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: My favorite looping mechanism in Perl is:

by Punto (Scribe)
on May 17, 2000 at 14:42 UTC ( [id://12061]=note: print w/replies, xml ) Need Help??


in reply to My favorite looping mechanism in Perl is:

Well, I come from Pascal, so I don't use those fancy loop things like "foreach", or "map".

If I want to go through an array I do:

for ($i = 0; $i<=$#array; $i++) { stuff; };
I also don't use $_ to get the contents of a file. I do this:
while ($line = <FILE>) { stuff; };
And I put ; at the end of every line..

Replies are listed 'Best First'.
Re: RE: My favorite looping mechanism in Perl is:
by BrentDax (Hermit) on Jul 06, 2001 at 10:20 UTC
    Uh...why?

    Personally, I find for-as-foreach more useful:

    for my $i(0..$#array) { #same thing as your C-like for stuff; }

    =cut
    --Brent Dax

    @HPAJ=split("", "rekcaH lreP rentonA tsuJ"); print reverse @HPAJ; #sucky but who cares?
      Personally, I find for-as-foreach more useful:

      Try make:

      for my $i (0 .. $#array) { ... }
      efficiently do something like:
      for ($i=0; $i < @array; $i += ROWSIZE) { ... }

        oh, you mean like

        for my $i ( grep { not $_ % ROWSIZE } 0 .. $#array )

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-20 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found