in reply to why does

No, reverse returns a list. When you assign that list to a hash, you coerce that list *into* a hash. Without that explicit coercion, you'll get an error.

This works:

print keys %{ { reverse %hash } };
but it's way ugly, and it's probably slower, since it takes an anonymous hash ref to the list returned by reverse, then dereferences that hash ref into a hash.

Replies are listed 'Best First'.
RE: Re: why does keys reverse %hash not work
by gumpu (Friar) on Aug 28, 2000 at 21:54 UTC

    Thanks

    On a side note, the full tittle of this post was supposed to be 'why does "keys reverse %hash" not work' both somehow everything after " dissapeared in thin air :)

    Have Fun

      I'll just address this quickly -- you lost everything after the double quote because you inadvertently screwed up how the browser reads the attribute values of the HTML. PerlMonks uses forms to collect input and send it back to the user. A well-coded text-box would look something like:

      <input type="text" name="title" value="some title">

      So the problem is, you've now tried to submit something like:

      <input type="text" name="title" value="why does "keys reverse %hash"">

      Obviously, whatever system PerlMonks is using on the backend barfs on the multiple double-quotes and just parses up to what it believes to be the closing quote.

      I'd imagine there's some good reason they can't perform a regexp and substitute a double quote out -- maybe they haven't had time, or maybe there's some other reason of which we are unaware.

      Regardless:

      &quot;

      (that's &-q-u-o-t-;) should work in titles.

      That, and other valuable pieces of info can be found at:

      Need Help?.

      Later.

        Thanks

        The odd thing is that it did show up in the preview.

        Have Fun.

        wouldn't the " be included in the title at the top of the browser though?
RE: Re: why does
by cwest (Friar) on Aug 28, 2000 at 23:58 UTC
    And, intuitivley, it should work. I helped suggest that keys(), values() and each() work on list in a DWIM manner for Perl 6 but, sadly, was shot down miserably.

    Why? Mostly because of prototype issues and supposed huge spead decreases as a result. I don't believe them fully, it could be done.

    Oh well... At least I found someone who uses Perl like I do, that's two for Tom ;-)

    --
    Casey
    
RE: Re: why does
by Anonymous Monk on Aug 29, 2000 at 20:22 UTC
    Why is %{{reverse %hash}} a "hash ref" rather than a hash? I understand that the Camel book on pg 246 uses this terminology. But it seems to me that %{{reverse %hash}} is an actual hash.
      You're right. The hash reference I was referring to is the intermediate result in that statement, created by
      { reverse %hash }
      That's an anonymous hash reference. The outer brackets not in the above statement then dereference that to create a hash.