timothy adigun <2teezp...@gmail.com> writes:

> Hi lee,
> Please, check my comment below:
>
> On Sun, Jun 23, 2013 at 3:43 AM, lee <l...@yun.yagibdah.de> wrote:
>
>> James Alton <jamesalton...@gmail.com> writes:
>>
>> > lee,
>> >
>> > You have a post statement if and then a code block. You can only use one
>> of
>> > two forms:
>> >
>> > print "test" if $color eq "blue"; #no parenthesis required
>> > if($color eq "blue"){print "test";}
>>
>> ++
>
>> And I can't have 'last if $color eq "blue" print "test\n";'?  That would
>> be something quite natural and a logical thing to do ...
>>
> logical? How is that? Wrap up, the function 'print' and 'last' in the if
> statement like so:
>   if( $color eq "blue"){
>      print "test\n";
>      last LABEL;
>   }

It's logical and expected because an 'if' statement goes like
'if(condition) { is_true; } else { is_not_true;}'.

Put a 'last' in front of the 'if' and the 'if' suddenly goes like
'if(condition_is_true) last;' and no more.

Flipping things around and breaking stuff like this is illogical and
unexpected.  The 'if' should still go like 'if(condition) { is_true; }
else { is_not_true;}', the only difference being that the prefixed
'last' is also executed when the condition is true and not when the
condition is not true.

When you think of a natural language like English, prefixing a word with
"not" doesn't change the meaning of the word that follows it, *and
particularly it does not change the way how the word is being used in
the language*.  Prefixing a "not" only changes the meaning of the
/sentence/, like "It is raining now and we need to close the windows."
vs. "It is not raining now and we do not need to close the windows.".

What perl does is like forbidding to use any more words after "raining"
and "need" for instances where "raining" or "need" is prefixed with
"not".  That's just a very silly thing to do because it creates a
different word (which is written exactly the same) the usage of which is
different from another word (which is written exactly the same).

Usually, words that have a different meaning and/or are being used in a
different way in a language aren't the same and are written differently.
Perl uses different words, but written exactly the same, with different
meanings, and they have different meanings because they are used
differently within the language (which is what makes them different
words). That leads to unexpected behaviour.

>> my $counter = 0;
>>
>> while($counter < 8) {
>>   next if($counter > 2);
>>   print "else: " . $counter . "\n";
>> }
>> continue {
>>   if($counter > 2) {
>>     print "if: " . $counter . "\n";
>>     last;
>>   }
>>   $counter++;
>> }
>>
>>
>> ... and is more efficient :)
>
>
> Which is?

else: 0
else: 1
else: 2
if: 3


-- 
"Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions."
http://www.joelonsoftware.com/items/2006/08/01.html

-- 
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