Larry Wall writes:
> On Mon, Mar 15, 2004 at 11:56:26AM -0700, John Williams wrote:
> : On Wed, 10 Mar 2004, Larry Wall wrote:
> : > You subscript hashes with {...} historically, or these days, Â...Â,
> : > when you want constant subscripts.  So what you're looking for is
> : > something like:
> : >
> : >     if / <?foo> ... <?baz> ... { $?foo{'baz'} ... $?baz } .../
> : > or
> : >     if / <?foo> ... <?baz> ... { $?fooÂbaz ... $?baz } .../
> : 
> : I'm probably a bit behind on current thinking, but did %hash{bareword}
> : lose the ability to assume the bareword is a constant string?
> 
> It's thinking hard about doing that.  :-)
> 
> : And why ÂÂ?  Last I heard that was the unicode version of qw(), which
> : returns an array.  Using an array constructor as a hash subscriptor is
> : not a "least surprise" to me.
> 
> We'd be trading that surprise for the surprise that %hash{shift} doesn't
> call C<shift>. 

And how often is that, compared with the frequency of doing
%hash{optname}, %hash{root}, etc?  %hash{~shift} isn't so bad, and it's
one of those quirks that people will just have to learn.  Perl has
plenty of those, and people don't mind once they know them.  I'm
grateful for most of them, now that I'm more experienced.

It's one of those things you'll have to mention when you talk about hash
subscripting, that's all.  After all, why isn't a hash subscripted with
[]? And why isn't the inside of a subscript a closure?  These are as
"inconsistent" as quoting a single {word}.

> Plus we get literal hash slices out of it for free.  Plus it also
> works on pair syntax :fooÂsome literal wordsÂ.  And probably trait and
> property syntax as well.
> 
> And basically because I decided :foo('bar') is too ugly for something
> that will get used as often as switches are on the unix command line.
> The %hash syntax is just a fallout of trying to be consistent with
> the pair notation.  Once people start seeing :fooÂbar all over,
> they won't find %hashÂbar surprising at all, and will appreciate the
> self-documenting literalness of argument.

Except the six extra keystrokes involved in typing them.  Yeah, I know,
I could reduce that, but Perl's already used up the rest of the
keyboard! :-)

Luke

Reply via email to