Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
We don't bite newbies here... much
 
PerlMonks  

Re^2: Loop Control

by slugman (Initiate)
on Jul 06, 2012 at 00:05 UTC ( #980186=note: print w/ replies, xml ) Need Help??


in reply to Re: Loop Control
in thread Loop Control

Yes, that is true Aaron. Thank you for the clever answer! I'm not quite sure how it works, so I'll have to run this in a few test scripts.. Your feedback is greatly appreciated :)


Comment on Re^2: Loop Control
Re^3: Loop Control
by aaron_baugher (Chaplain) on Jul 06, 2012 at 02:10 UTC

    You're welcome. The confusing part there might be the ternary operator, which you can learn more about in perlop, under Conditional Operator. It's more-or-less an if-then-else conditional, but since it's a single expression, it's easier to plug into a print statement like that. If Perl didn't have it, I'd probably do the same thing with something like this:

    { # start a block to limit the va +riable's scope my $maybe_a_slash = ''; # default to no slash $maybe_a_slash = '/' if $i; # make it a slash if counter ha +s incremented print "$a[$i]$maybe_a_slash$c1[$w]"; } # end the block

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2013-05-19 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (397 votes), past polls