in reply to regarding hash keys

The only reason you need to explicitly quote the Left Hand Side of the => operator is if the key contains white space*:
my %hash = ('key 1' => 'value1');
Off-Topic:
I have to note that PHP also has the arrow operator and it works in the same mannor. However, PHP is "broken" in the sense that you have to quote any keys that are reserved words. For example:
$hash = array( title => 'Hello World', 'class' => 'this key has to be explicitly quoted', );
Also note that PHP allows trailing commas, but not in a function parameter list. Crazy.

UPDATE: silly /me - you need to quote keys that contain \W (that is, non alpha-numeric). Thanks liz and Anonymous Monk. :)

UPDATE 2: thanks for catching that YuckFoo

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: regarding hash keys
by liz (Monsignor) on Sep 09, 2003 at 15:32 UTC
    Almost the only reason ;-)

    use strict; my %a = ( a::b => 1 );
    gives:
    Bareword "a::b" not allowed while "strict subs" in use at line 2
    
    This error occurs as far back as 5.00503 and as recent as 5.8.1.

    Liz

Re: Re: regarding hash keys
by Anonymous Monk on Sep 09, 2003 at 15:42 UTC
    Well, if any of your characters are operators then the keys need to be quoted as well:
    my %hash = ( part-1 => 'once upon a time', part-2 => 'in a galaxy far far away'); print keys %hash;
Re: Re: regarding hash keys
by YuckFoo (Abbot) on Sep 09, 2003 at 21:08 UTC
    > you need to quote keys that contain \W

    Seems you also need to quote keys that have leading digits followed by non-digits.

    my %hash = ( 1 => 'foo', # ok key1 => 'bar', # ok 1key => 'baz', # error );

    YuckFoo

      Not always :-)

      %h = (1e3 => 'foo'); print keys %h;
      1000