On Jun 27, 2013, at 2:39 AM, lee wrote:

> John SJ Anderson <geneh...@genehack.org> writes:
> 
>> Lee, have you read the 'statement modifiers' and 'compound statement'
>> portions of 'perldoc perlsyn'? You may find that this clarifies this
>> issue for you.
> 
> Well yes, I understand that there are two different kinds of 'if' one of
> which is kinda broken (but nonetheless quite useful), and that doesn't
> prevent me from thinking that an 'if' should always work as an 'if' :)

The statement modifier 'if' is not broken. It is working as designed. I use it 
all the time to write elegant, readable, and maintainable code.

'if' is not the only allowable statement modifier. The others are:

unless
while
until
for
when

All of these simple statement modifierss have their counterparts in compound 
statements (e.g. 'if (EXPR) BLOCK' ).

Note that the statement modifier syntax allows you to write a do-while or 
do-until loop, where at least one pass is made through the loop before the loop 
termination test is performed:

do {
  …
} while condition();

The while here is a statement modifier, and the do{} is a single statement with 
one or more internal statements grouped as one.

Beginners to Perl would be advised to learn the syntax and how it can be used 
to write powerful, elegant programs in fewer statements than other languages. 
That is why we like Perl and use it whenever we can.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to