On Mon, Jun 24, 2013 at 08:20:57PM -0700, John W. Krahn wrote:
> The parentheses in this case do nothing, and they certainly don't
> imply that last is a function.
> 
> $ perl -le'
> use warnings;
> use strict;
> for (1..2) {
>     ();
>     }

In this case I'd guess that the parenthesis would be interpretted
as an empty list in void context. Next to a next or last
statement though that seems to make zero sense so it seems odd
that it would be allowed at all.

I didn't say that this implies that last is a
function/subroutine. :) Only that it appears to behave like one
sometimes.

> That won't work:
> 
> $ perl -le'
> use warnings;
> use strict;
> while () {
>     my_last;
>     }
> sub my_last {
>     last;
>     }
> '
> Bareword "my_last" not allowed while "strict subs" in use at -e line 5.
> Execution of -e aborted due to compilation errors.
> 
> 
> And even if you fix that bareword you still get a warning:
> 
> $ perl -le'
> use warnings;
> use strict;
> while () {
>     my_last();
>     }
> sub my_last {
>     last;
>     }
> '
> Exiting subroutine via last at -e line 8.

Touché. :) Apparently I left out strict and warnings from my
one-liners and carelessly translated them into strict programs
without verifying... :-[ Thanks for catching my mistakes.

Nevertheless, it still works, but it warns you about it if you
enable warnings (and the subroutine call causes compilation to
fail with strict subs).

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to