Bill,

Below statement wont be helpful for lee, as he has requirement to loop at
least one time.
############
 last if ($counter > 2);

where as below one is working:

############
if ( $counter > 2) {
  print 'if : ' . $counter . "\n";     #could do print "if : $counter\n" as
well
  last;
}



On Mon, Jun 17, 2013 at 6:43 PM, bill pemberton <wape...@gmail.com> wrote:

> I think the rest after the 'if' for the last is wrong. either do this:
>    last if ($counter > 2);
>
> or
>
> if ( $counter > 2) {
>   print 'if : ' . $counter . "\n";     #could do print "if : $counter\n"
> as well
>   last;
> }
>
>
> On Mon, Jun 17, 2013 at 8:56 AM, lee <l...@yun.yagibdah.de> wrote:
>
>> Hi,
>>
>> trying to figure out what `last' actually does, I wrote this test
>> script:
>>
>>
>> use strict;
>> use warnings;
>> use autodie;
>>
>> my $counter = 0;
>>
>> while($counter < 8) {
>>     last if($counter > 2) {
>>         print "if: " . $counter . "\n";
>>     }
>>     else {
>>         print "else: " . $counter . "\n";
>>     }
>>     $counter++;
>> }
>>
>>
>> Unfortunately, that gives syntax errors.  I would expect the following
>> output:
>>
>>
>> else: 0
>> else: 1
>> else: 2
>> if: 3
>>
>>
>> What's wrong with that (letting aside that it is terribly ambiguous)?
>>
>>
>> --
>> "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/
>>
>>
>>
>
>
> --
> wapembe
> seller of truths, half and whole
> inquire about quantity discounts!
>

Reply via email to