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

delete hash slice from a hashref wont return vals?

by misterperl (Pilgrim)
on Aug 21, 2013 at 14:26 UTC ( [id://1050357]=perlquestion: print w/replies, xml ) Need Help??

misterperl has asked for the wisdom of the Perl Monks concerning the following question:

Things that make u go HUH..

I'm trying something like:

($cgi is a hashref, @KEYS = keys %$cgi)

If I try:

die join ',',@$cgi{@KEYS}

I get a list of values from the hash, as expected. All is good.

BUT, if I try

my @vals = delete @$cgi{@KEYS}

I get an array of length @KEYS, each element empty ( eq ''), even though the array has values I can see in the die? delete should return an array of the values from the deleted slice?

I humbly seek counsel. I don't get it.

PS I should have mentioned - YES, the hash elements are indeed deleted... I just cant get the vals back....

Replies are listed 'Best First'.
Re: delete hash slice from a hashref wont return vals?
by hdb (Monsignor) on Aug 21, 2013 at 14:37 UTC

    It works for me:

    use strict; use warnings; my $cgi = { a => 1, b => 2 }; my @keys = keys %$cgi; my @vals = delete @$cgi{ @keys }; print "@vals\n";

    prints "1 2"

      Yes I got it to work in a small example too. I'm starting to think it has something to do with the fact that im revisiting the page and $cgi may be somehow getting altered in a way I'm not seeing.

      Thanks for the reply sir!
Re: delete hash slice from a hashref wont return vals? (dumper)
by Anonymous Monk on Aug 21, 2013 at 15:34 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found