Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Easiest way to do something only on first iteration of loop

by AnomalousMonk (Archbishop)
on May 07, 2016 at 01:14 UTC ( [id://1162422]=note: print w/replies, xml ) Need Help??


in reply to Easiest way to do something only on first iteration of loop

c:\@Work\Perl\monks>perl -wMstrict -e "my $arrayref = [ 'The quick', 'brown fox jumped', 'over the lazy dog. +', ]; ;; for my $i (0 .. $#$arrayref) { printf ' ' x 6 if $i == 0; print qq{$arrayref->[$i] \n}; } " The quick brown fox jumped over the lazy dog.
Sweeten with
    ... unless $i == 0;
or
    ... if $i != 0;
etc. to taste. (Doesn't require 5.10+.)


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-23 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found