develooper Front page | perl.perl5.porters | Postings from June 2012

Re: [perl #113554] my() with empty list causes weird error

Thread Previous | Thread Next
From:
Eric Brine
Date:
June 26, 2012 11:46
Subject:
Re: [perl #113554] my() with empty list causes weird error
Message ID:
CALJW-qG42LN==z+_o+2rc_7eHMNCs2bScw+1itdVVTea1JecpA@mail.gmail.com
On Tue, Jun 26, 2012 at 7:44 AM, demerphq <demerphq@gmail.com> wrote:

> but should it really allow:
>
> printf "%d", my(), my(), my(), my(), my $x=10, my();
>

I'm not sure what argument you're making, but it appears to be an appeal to
aesthetics. If so, the argument equally applies to

printf "%d", do{}, do{}, do{}, do{}, $x=10, do{};

which we're not going to change, so that leaves me answering "yes, that's
not a reason for forbidding my()".


On the other hand, arguments about consistency are not very convincing. my
is very particular (i.e. exceptional) as to what it accepts as arguments.

$ perl -e'my ( $foo{x} )'
Can't declare hash element in "my" at -e line 1, at EOF
Execution of -e aborted due to compilation errors.

So preventing C<< my () >> can catch errors (as it did in the code
generator that was mentioned).


The question is: Can it also prevent legitimate code? I actually came up
for a use for C<< my () >>: Self documenting lack of arguments.

sub foo {
    my () = @_;
    ...
}

- Eric

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About