Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl: the Markov chain saw
 
PerlMonks  

Re: XML Bare Hash Reference.

by Eliya (Vicar)
on Mar 19, 2013 at 18:18 UTC ( #1024353=note: print w/ replies, xml ) Need Help??


in reply to XML Bare Hash Reference.

I think you should just remove the % in

return map $_->{'value'}, @{%$hash}{@_}; ^

Starting with 5.10, Perl changed (fixed) the way this hash-slice construct is interpreted, which would explain why it did work before upgrading...

(As there's no test for xget in the package, presumably no one has come across the issue yet.)

#!/usr/local/bin/perl -w use strict; sub xget { my $hash = shift; return map $_->{'value'}, @{%$hash}{@_}; } my $hash = { foo => { value => "FOO" }, bar => { value => "BAR" }, }; print "$_\n" for xget($hash, qw(foo bar) );
$ ./1024343.pl Can't use string ("2/8") as a HASH ref while "strict refs" in use at . +/1024343.pl line 9.

Fixed:

#!/usr/local/bin/perl -w use strict; sub xget { my $hash = shift; return map $_->{'value'}, @$hash{@_}; } my $hash = { foo => { value => "FOO" }, bar => { value => "BAR" }, }; print "$_\n" for xget($hash, qw(foo bar) );
$ ./1024343.pl FOO BAR


Comment on Re: XML Bare Hash Reference.
Select or Download Code
Re^2: XML Bare Hash Reference.
by huchister (Acolyte) on Mar 19, 2013 at 18:41 UTC
    Appreciate, Got to check out why / how hash-slice construct being interpreted.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-04-20 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (486 votes), past polls