Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

XML Bare Hash Reference.

by huchister (Acolyte)
on Mar 19, 2013 at 17:28 UTC ( #1024343=perlquestion: print w/ replies, xml ) Need Help??
huchister has asked for the wisdom of the Perl Monks concerning the following question:

I'm having another problem regarding with hash reference after upgrading perl version from 5.8.8 to 5.10.2

New Perl version seems not accepting below code

All modules are using XML::Bare..., I was hoping is there another way to get around with this.
(Instead of using different CPAN module, since almost every single perl scripts using XML::Bare at moment.

Error Message Below:
Can't use string ("7/16") as a HASH ref while "strict refs" in use at /usr/lib64/perl5/vendor_perl/XML/Bare.pm line 67.

Here is what line 67 from XML / Bare.pm is about
sub xget { my $hash = shift; return map $_->{'value'}, @{%$hash}{@_}; }

Thanks.

Comment on XML Bare Hash Reference.
Download Code
Re: XML Bare Hash Reference.
by toolic (Chancellor) on Mar 19, 2013 at 17:59 UTC
    Are you using the latest version of XML::Bare? If not, maybe it is a bug which has been fixed.

    How are you calling xget in your code?

      I've checked out the latest version, but it seems problem still occurs. No change upon the xget function, Here is the link to the XML-Bare github

      Click Here for XML-Bare

        The version on github is the same as on cpan. The question asked of you "How are you calling xget in your code?", the answer to which may help investigations.

Re: XML Bare Hash Reference.
by Eliya (Vicar) on Mar 19, 2013 at 18:18 UTC

    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
      Appreciate, Got to check out why / how hash-slice construct being interpreted.
Re: XML Bare Hash Reference.
by AnomalousMonk (Monsignor) on Mar 19, 2013 at 20:28 UTC

    Please check out the discussion in the Hash statement problem. thread. The basic problem is still that the  %$hash_reference syntax (and I think also the  @$array_reference syntax) simply doesn't work (Update: within a hash/array slice expression as shown in the OP – thanks, choroba) from version 5.10.x (where x == 0, I think) onward.

    Wherever you find if, you will have to change this syntax as has been noted elsewhere in this and the previous thread – or else get the maintainer(s) of the module(s) in question to change it, which is probably more trouble than just changing it yourself!

      %$hash_ref and @$array_ref still work. It is @{%$hash_ref}{1,2} which does not work anymore, as it never should have worked. %$hash_ref is evaluated to a string like "1/8" which tells you how the hash uses its buckets. Then, @{"1/8"}{1,2} tries to interpret the string as a hash reference and fails. Without strict refs, you can create a hash called "1/8": ${"1/8"}{1} = "q"; print @{"1/8"}{1};
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: XML Bare Hash Reference.
by codechild (Initiate) on Apr 26, 2013 at 18:39 UTC
    This is in fact a bug in the module due to changes within Perl. The latest version of the module has been fixed to correct this.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-08-01 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (36 votes), past polls