Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How do I push new data into an existing hash?

by juo (Curate)
on Apr 19, 2001 at 13:23 UTC ( [id://73780]=note: print w/replies, xml ) Need Help??


in reply to How do I push new data into an existing hash?

I want to add something to an existing key of a hash. $hash{key}=$val; will replace the content of key with a new content $val but will not add $val to the already existing content of key. If I try to use push to add the new value to the exisiting content then perl will give an error message : Type of arg 1 to push must be array (not hash elem.
  • Comment on Re: How do I push new data into an existing hash?

Replies are listed 'Best First'.
Re: Answer: How do I push new data into an existing hash?
by arturo (Vicar) on Apr 19, 2001 at 19:23 UTC

    Try $hash{$key} .= $val; if $hash{$key} is a (string) scalar, or push @{$hash{$key}}, $val if $hash{$key} is an array reference. See perldoc perlref and perldoc perlreftut for more on how to play with references.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2026-01-14 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.