FAQ
Hi,

I'm parsing an xml file and get an error when dereferencing a hash. I get an
error saying "Not a HASH reference as line 15."
Not sure where my syntax is off.

thanks,

galeb


My script is:

#!/usr/local/bin/perl
# parse_xml_OMap.pl
use strict; use warnings;
use Data::Dumper;


use XML::Simple;
my $xs = XML::Simple->new;
my $ref = $xs->XMLin(@ARGV);


my $ref2array = $ref->{'RESTRICTION_MAP'}->{'FRAGMENTS'}->{'F'}; #LINE 15

print $ref2array, "\n";



foreach my $ref_2_frag_hash (@{$ref2array}){

my $I = $ref_2_frag_hash->{'I'} +1;
my $S = $ref_2_frag_hash->{'S'};


print "$I\t$S\n";
}

Search Discussions

  • Jim Gibson at Nov 3, 2010 at 10:07 pm
    On 11/3/10 Wed Nov 3, 2010 1:13 PM, "galeb abu-ali" <abualiga2@gmail.com>
    scribbled:
    Hi,

    I'm parsing an xml file and get an error when dereferencing a hash. I get an
    error saying "Not a HASH reference as line 15."
    Not sure where my syntax is off.
    Your syntax is fine. What is wrong is that one of the elements of your
    complex data structure is not a hash as you expected.

    Print the contents of the structure using Data::Dumper:
    My script is:

    #!/usr/local/bin/perl
    # parse_xml_OMap.pl
    use strict; use warnings;
    use Data::Dumper;


    use XML::Simple;
    my $xs = XML::Simple->new;
    my $ref = $xs->XMLin(@ARGV);
    print Dumper($ref);
  • Galeb abu-ali at Nov 4, 2010 at 1:52 pm
    thanks, you're right. I took another look at the data structure and got the
    script to work.
    On Wed, Nov 3, 2010 at 6:07 PM, Jim Gibson wrote:

    On 11/3/10 Wed Nov 3, 2010 1:13 PM, "galeb abu-ali" <abualiga2@gmail.com

    scribbled:
    Hi,

    I'm parsing an xml file and get an error when dereferencing a hash. I get an
    error saying "Not a HASH reference as line 15."
    Not sure where my syntax is off.
    Your syntax is fine. What is wrong is that one of the elements of your
    complex data structure is not a hash as you expected.

    Print the contents of the structure using Data::Dumper:
    My script is:

    #!/usr/local/bin/perl
    # parse_xml_OMap.pl
    use strict; use warnings;
    use Data::Dumper;


    use XML::Simple;
    my $xs = XML::Simple->new;
    my $ref = $xs->XMLin(@ARGV);
    print Dumper($ref);



    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedNov 3, '10 at 8:14p
activeNov 4, '10 at 1:52p
posts3
users2
websiteperl.org

2 users in discussion

Galeb abu-ali: 2 posts Jim Gibson: 1 post

People

Translate

site design / logo © 2021 Grokbase