On Thursday 03 Feb 2011 10:30:22 Avishalom Shalit wrote:
> 'key' is better . because it is explicit
> the bareword  in {key}
> is translated into the string 'key'

Actually, they are both equivalent. Like you said ->{key} is translated into 
->{'key'} which is how Perl behaves.

> 
> unless you are using "strict"
> which would disallow barewords.

strict, however, still allows barewords inside hash subscripts, and converts 
them to strings automatically, so there is no harm in using it without the 
'...' and it actually adds less clutter to the code. 

Another point to consider is that if you are using these for accessing the 
slots/fields/attributes/member-values of objects, you should be using 
accessors instead:

http://www.shlomifish.org/lecture/Perl/Newbies/lecture5/accessors/

Regards,

        Shlomi Fish

> 
> 
> -- vish
> 
> On 3 February 2011 09:28, Chanan Berler <bc.ot...@gmail.com> wrote:
> > Hello All
> > 
> > I wonder what is best usage: using 'key' or key (no quotes).
> > will using 'key' means Perl creates a string, before retrieving the
> > hash pointer value ? or Perl parser is parsing out the ' characters
> > 
> > my $value = $obj->{'key'};
> > 
> > or
> > 
> > my $value = $obj->{key};
> > 
> > thanks
> > Chanan
> > 
> > --
> > ===================
> > ----     Chanan Berler    ----
> > ===================
> > _______________________________________________
> > Perl mailing list
> > Perl@perl.org.il
> > http://mail.perl.org.il/mailman/listinfo/perl
> 
> _______________________________________________
> Perl mailing list
> Perl@perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://shlom.in/humanity

Chuck Norris can make the statement "This statement is false" a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Perl mailing list
Perl@perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to