On Mon, Mar 15, 2004 at 07:54:09PM -0700, Luke Palmer wrote: : 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.
Yeah, and guess who had to trust his gut-level feelings for that? :-) : 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}. Well, all context dependencies are created equal, but some are more equal than others... : > 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! :-) It's really the visual disambiguation that convinces me. It's extra keystrokes for me too, y'know, and my finger joints complain to me every day. I mostly just ignore 'em, but they do make a fearful crackling most of the time... But my eyes are bad too, so I have to cater to them too... But really, it's my brain that's my weakest organ, and I can't fix that, so I figure I'll just have to feature it. Larry