Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How many loops are there in Perl?

by JavaFan (Canon)
on Jan 31, 2012 at 07:29 UTC ( #950901=note: print w/replies, xml ) Need Help??


in reply to How many loops are there in Perl?

$i = 10;L: print "Hello"; goto L if --$_i; map {print "Hello"} 1 .. 10; grep {print "Hello"} 1 .. 10; $_ = "abcdefghij"; s/./@{[print "Hello"]}/g; sub foo { print "Hello"; foo($_[0]-1) if $_[0] > 0; } foo(10);

Replies are listed 'Best First'.
Re^2: How many loops are there in Perl?
by tobyink (Abbot) on Jan 31, 2012 at 08:23 UTC

    In the spirit of your map and grep examples, here's one using sort...

    perl -E'join("|", sort {do{say "Inside sort loop"} and $a <=> $b} 3,1, +2)'

    Works in 5.10.1, but the Perl sorting algorithm has been known to change from version to version. Note that the join does seem to be needed to avoid Perl optimizing away the sort.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950901]
help
Chatterbox?
[1nickt]: So decadent, I love it! "Frequently bought together ..." the biscuits *and* the spread ;-)
[virtualsue]: we had it in belgium a few years ago then realised you could buy it everywhere in the uk

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-11-20 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (286 votes). Check out past polls.

    Notices?