Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: •Re: Re: %h->{foo} vs. $h{foo}..

by smferris (Beadle)
on May 30, 2003 at 20:49 UTC ( [id://261940]=note: print w/replies, xml ) Need Help??


in reply to •Re: Re: %h->{foo} vs. $h{foo}..
in thread %h->{foo} vs. $h{foo}..

Sorry.. Not trying to beat a dead horse here.. But I don't think it's fair to call it a bug either.. not if something similar is being implemented in Perl6. %foo.{key} is different from %foo->{key}? Both let you access a hash as a hashref, rather than as a hash. (I'm assuming this is the source of my confusion. something I don't know about the Perl6 implementation, perhaps?)

Un-Intentional, perhaps.. but a bug? Of course, I've never looked at more than a few lines of the source.. so I'm no-one to argue. 8) and please don't take it as such.. I really am just trying to see the big picture here.

I love Perl and being bashed for something stupid I've done only makes me better.. right? ;D (provided I learn from it, of course) But.. Just to clear my point of view a little further: (Bare with me, this is long, I apologize)

For instance, take a 1000 new Perl coders.. Explain that $ represents a scalar, and % represents a hash structure.. (Incomplete, I will not disagree.. but still a true statement) Now give them the code:

1> $foo='bar'; 2> $foo{'bar'}='baz!'; 3> %foo=('calvin','hobbes');

Ask them what foo represents on each line. (a hash or scalar) For the experienced perl coder, no problem. For the unexperienced, I'll bet the number of wrong answers isn't zero. (Line 2 being the one likely confused of course) Now give them the code:

1> $foo='bar'; 2> %foo->{'bar'}='baz!'; 3> %foo=('calvin','hobbes');

Ask again.. I'll bet their accuracy is a bit better.. My opinion is, the unexperienced perl coder could probably go their whole life w/o knowing about, or at least understanding refs and still write code that worked for them. Perfect example... back in the Perl 4 days.. A collegue of mine showed ME what a hash was.. Some 7-8 years later, I find myself trying to explain a hashref to them because they're trying to copy a hash (HOH) with $a{1}=$b{1} and they can't figure out why they can't modify $b{1} w/o affecting $a{1}.. But yet.. It's taken them almost 8 years to discover it. 8) (And I know they're still confused by them) I know they've used modules before and have had to instantiate them, so, indirectly they knew about 'em.. They were just unaware of them.

As for the experienced, it may not look right, but I'll bet the number of wrong answers is closer to 0.. or at least much closer than the newb people with the initial code.

Heck, Exegesis 2 is the reason I even tried %foo->{blah} to begin with.. I thought, Hmmm, what if that was available now, in 5.6.1? Let's try it.. Get used to using it.. and, Wow.. whataya know. it worked!

Replies are listed 'Best First'.
•Re: Re: •Re: Re: %h->{foo} vs. $h{foo}..
by merlyn (Sage) on May 30, 2003 at 21:02 UTC
    But I don't think it's fair to call it a bug either.. not if something similar is being implemented in Perl6.
    No, that doesn't fly with me. There are hundreds of new syntax forms in Perl6.

    In Perl5, the closest interpretation you could apply to %foo->{$bar} is "treat %foo in a scalar context" (which returns the N-over-M bucket usage string) "then dereference that" (as a string, it'd have to be a soft reference) "as a hash reference, and take the element with the key of $bar".

    Sorry, that's just next to useless. And the implementers agreed. The only reason it worked is because %foo left the reference to foo on the stack for things like hash functions (keys, each, etc), and then the dereference arrow couldn't tell whether it was a reference from a real referencing, or from the literal name.

    So, it worked only because it wasn't disallowed, as it should have been disallowed.

    Please stop bringing irrelevant items into the discussion. Perl6 syntax is Perl6 syntax. Perl5 syntax had a meaning for that syntax, except the implementation was broken, and the meaning was almost always not what people accidentally typed. Hence, it is now just becoming forbidden to deal with all possible mistakes.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Hmmm.. Interesting.. Now I see why it's considered a bug. Glad you could set me straight. 8)

      But.. irrelevant? That's your point of view and I will not stop.. I started the node? I could turn it into a discussion about pink elephants in green tu-tu's! Ok.. that's irrelevant.. and not something I'd do on perlmonks. (Or will I?) ;D

      My point is.. If I make a mistake.. Point out my mistake and move on.. knowing that it's a mistake I'll likely not make again. but please don't ask me not to try and understand a problem or make a comment that may help someone understand my point of view.

      If I don't ask.. I wont learn.. If I don't learn.. what's the point of this forum? It took one node Assining data to an array is slow.. to help me understand context and optimize a 6.5 hour process to under 30 minutes. That question was completely irrelevant to that project.. or was it? Sometimes answers WILL cascade into other answers.. Purely by mistake.

      Ok.. time to put this thread to rest.. Thanks for the discussion.. Believe it or not.. I have walked away with something.. I apologize if I have wasted anyones time. Just add me to your 'to filter' list. ;D

      Regards,
      SMF

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://261940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-05-30 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.