Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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!

Replies are listed 'Best First'.
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.



      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981556]
[choroba]: It has the widest rear seats space available in the same price category - needed for the 3 kids.
Discipulus families growth is related to price of cars nowadays..
[choroba]: price of anything, unfortunately
[Discipulus]: yes, unfortunately.
[Corion]: Discipulus: you can "easily" trap shutdown/logoff in a Win32::GUI application by capturing and responding to the appropriate message
[LanX]: choroba wants to scale further? :)
[Discipulus]: I read an article about how much the female condition has got worst in the eastern europe after the fall of social policies
LanX has a friend in Berlin who switched to go(lang) and just got a kid ...
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-01-17 09:45 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (154 votes). Check out past polls.