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

Re: [perl #56150] return return

Thread Previous | Thread Next
From:
Mark Mielke
Date:
June 23, 2008 10:51
Subject:
Re: [perl #56150] return return
Message ID:
485FE2A6.302@mark.mielke.cc
Aristotle Pagaltzis wrote:
> Btw, why did you use quotes in `$this->{'foo'}`? They’re not
> required.
>   

Easy. I don't trust Perl, and (unfortunately) our code needs to run on 
Perl 5.004 and before.

If somebody can convince me that all versions of Perl 5.004 and later 
will ALWAYS treat 'foo' as literal without quotes in this context, I'll 
be happy to drop it. It may have been Perl earlier than 5.004 that 
sometimes did unexpected things with:

    $foo{time} = 2;

As it is, the following fails for me today:

> $ perl -e '$f{my-variable} = 1; print "$f{my-variable}\n"'
> syntax error at -e line 1, near "my-"
> syntax error at -e line 1, near "my-"
> Execution of -e aborted due to compilation errors.

Probably because the '-' triggers it to run in expression mode. 
Sometimes we use '-' instead of '_', or even a space character or ':' in 
the key value. These won't work for certain. Better to consistently use 
quotes everywhere.

Such is my opinion and style. Is it comparable to return vs not? It's 
similar but not the same. In the case of consistent quoting, it means I 
can use all values without worrying about it failing for me one day. In 
the case of return, both work fine and will not fail one day.

Cheers,
mark

-- 
Mark Mielke <mark@mielke.cc>


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