Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

delete hash slice from a hashref wont return vals?

by misterperl (Acolyte)
on Aug 21, 2013 at 14:26 UTC ( #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....

Comment on delete hash slice from a hashref wont return vals?
Re: delete hash slice from a hashref wont return vals?
by hdb (Parson) 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
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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-07-14 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls