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 (Canon) 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.