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!


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.