Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: can I change hash keys or values directly

by AnomalousMonk (Archbishop)
on Jan 29, 2021 at 00:53 UTC ( [id://11127614]=note: print w/replies, xml ) Need Help??


in reply to can I change hash keys or values directly

... is there a perlVar or function that is the TRUE array of hash key ... that,when changed, changes the keys ...

Others have answered this in the negative and explained why it can't be done. In support, consider that a hash (or associative array) key is an index of the array. Would you expect that in a positional array @ra there would be some way to directly operate on the index of element $ra[1] (i.e., 1) to change it to, say, 42 and expect the element to change its position in the array correspondingly? I suppose this kind operation is conceivable, but the fact that it doesn't exist in any language (AFAIK) suggests its inutility. (Update: I'd be interested to know if there's a language with an operator like this for either type of array.)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: can I change hash keys or values directly
by GrandFather (Saint) on Jan 29, 2021 at 02:15 UTC

    Don't say that too loud or you'll be seeing it in PHP!

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re^2: can I change hash keys or values directly (Lisp)
by LanX (Saint) on Jan 29, 2021 at 14:07 UTC
    > I'd be interested to know if there's a language with an operator like this for either type of array.)

    Short: alists in Lisp allow this

    Long: Dunno if there is an "operator", but Lisp has various approaches to associative arrays and alists are the most basic. They are basically just lists of "pairs" with linear search, hence slow.

    Disclaimer: my Lisp is eLisp

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    PS: obligatory Xkcd ;)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found