Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: list item comparison

by nitin1704 (Sexton)
on Jul 13, 2012 at 04:49 UTC ( #981556=note: print w/ replies, xml ) Need Help??


in reply to Re^3: list item comparison
in thread list item comparison

Yes, it's easier to understand the way you presented it. The one line syntax (statement modifier form) is fairly common in Perl though, and it's great if beginners can pick it up. @OP: This syntax can be used with both loops and conditions. E.g:

if($cond){ doSomething(); }

can be replaced by:

doSomething() if $cond;

The only catch is that you can execute only one statement per iteration/condition with this syntax. Happy coding!


Comment on Re^4: list item comparison
Select or Download Code
Re^5: list item comparison
by johngg (Abbot) on Jul 13, 2012 at 08:52 UTC
    The only catch is that you can execute only one statement per iteration/condition with this syntax.

    That's where do blocks come in handy :-)

    knoppix@Microknoppix:~$ perl -E ' > $sayIt = 1; > do { > say q{Hello}; > say q{World}; > } if $sayIt;' Hello World knoppix@Microknoppix:~$

    I hope this is of interest.

    Cheers,

    JohnGG

      There's always something to learn! Thanks John. I'm a beginner too by the way, started learning Perl a couple of months ago.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2014-07-13 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (247 votes), past polls