http://www.perlmonks.org?node_id=1022855

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

On my upgrade system, one of my hash statement fails to execute.

Declaring two variables,

my( $rxml, $ob ) = @{%$self}{qw/rxml rxml_ob/};

Above statement not seems to be working anymore.

I'm currently using perl v5.8.8.

Should I separate $rxml, $ob values? or would there be alternative solution to make this statement to be compatible with current perl version.

UPDATE(3/12/2013): Problem solved.

For more information,
$self contains:
my $self = bless( { 'rxml' => 'test', 'rxml_ob' => 'test2' } );

Problematic line:
my( $rxml, $ob ) = @{%$self}{qw/rxml rxml_ob/};
While I upgrade perl version from 5.8.8 to 5.10.1 gives me this error.

Can't use string ("30/64") as a HASH ref while "strict refs" in use at

Solution:
my( $rxml, $ob ) = @{$self}{qw/rxml rxml_ob/};
Disgard % hash sign.

It seems first statement wasn't even working at 5.8.8 and do not provide any strict ref errors. 5.10.1, perl seems became more strict about this.

Thanks to cristofo and Anamolusmonk for clarification and answer to my question promptly,
(though I gave out the limit amount of info, these guys nailed down my problem and guided me to right direction. also, I thank you all for your prompt attention!)

Replies are listed 'Best First'.
Re: Hash statement problem.
by Cristoforo (Curate) on Mar 11, 2013 at 19:53 UTC
    Change @{%$self}{qw/rxml rxml_ob/} to @{$self}{qw/rxml rxml_ob/} without the %.
Re: Hash statement problem.
by AnomalousMonk (Archbishop) on Mar 12, 2013 at 01:13 UTC

    The usage you show is a xenomorph that escaped into the general population a long time ago and was finally hunted down and extirpated somewhere between 5.8.9 and 5.10.1. It did not reproduce, so you can relax.

    >perl -wMstrict -MData::Dump -le "print $]; ;; my $self = { qw(rxml rxml_i_am rxml_ob rxml_ob_it_is) }; dd $self; ;; my( $rxml, $ob ) = @{%$self}{qw/rxml rxml_ob/}; print qq{'$rxml' '$ob'}; " 5.008009 { rxml => "rxml_i_am", rxml_ob => "rxml_ob_it_is" } 'rxml_i_am' 'rxml_ob_it_is'
    >perl -wMstrict -MData::Dump -le "print $]; ;; my $self = { qw(rxml rxml_i_am rxml_ob rxml_ob_it_is) }; dd $self; ;; my( $rxml, $ob ) = @{%$self}{qw/rxml rxml_ob/}; print qq{'$rxml' '$ob'}; " 5.010001 { rxml => "rxml_i_am", rxml_ob => "rxml_ob_it_is" } Can't use string ("2/8") as a HASH ref while "strict refs" in use at - +e line 1.
      Superb! Thank you for clarify my problem.
Re: Hash statement problem.
by kcott (Archbishop) on Mar 11, 2013 at 20:53 UTC

    G'day huchister,

    You have a syntax error in your use of a hash slice. Cristoforo has shown you the fix;See Update below perldata - Slices provides an explanation.

    Update: That looked like a simple syntax error to me but apparently it's not:

    $ perl -MO=Deparse,-p -e 'my( $rxml, $ob ) = @{%$self}{qw/rxml rxml_ob +/};' (my($rxml, $ob) = @{%$self;}{'rxml', 'rxml_ob'}); -e syntax OK

    The suggested "fix" by Cristoforo shows the more usual form:

    $ perl -MO=Deparse,-p -e 'my( $rxml, $ob ) = @{$self}{qw/rxml rxml_ob/ +};' (my($rxml, $ob) = @{$self;}{'rxml', 'rxml_ob'}); -e syntax OK

    Please elaborate on "not seems to be working anymore" and advise what data $self refers to.

    -- Ken

      :) except that its perfectly valid syntax, thus, not a syntax error
Re: Hash statement problem.
by Anonymous Monk on Mar 11, 2013 at 19:52 UTC

    Above statement not seems to be working anymore.

    What does that mean? See Basic debugging checklist

    Should I separate $rxml, $ob values? or would there be alternative solution to make this statement to be compatible with current perl version.

    What makes you think it isn't compatible? That fact is not in evidence :)

Re: Hash statement problem.
by blue_cowdawg (Monsignor) on Mar 11, 2013 at 20:32 UTC
        Above statement not seems to be working anymore.

    what was your expected result?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Hash statement problem.
by sundialsvc4 (Abbot) on Mar 11, 2013 at 21:39 UTC

    Also, I can pretty much predict that your program does not say:
    use strict;
    use warnings;

    Because if it did, you would be getting this:
    Can't use string ("0") as a HASH ref while "strict refs" in use ...

    In your original post, there are many key details missing:   you said that you did an “upgrade,” but not from what to what.   The code you provided, as noted, probably would not have worked anyway.   Details are absolutely everything.

      Upgrade to Perl Version 5.8.8 to Version 5.10.12.