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

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

Thread Previous | Thread Next
Eric Brine
June 26, 2012 11:46
Re: [perl #113554] my() with empty list causes weird error
Message ID:
On Tue, Jun 26, 2012 at 7:44 AM, demerphq <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About