Hi monks I am using XML::Simple module for parsing my attached xml data. I wrote mentioned code for fetching query data value. It is working fine. But it is giving this error “Can't use string ("GENERATE EXPRESS STATIST") as a HASH ref while "strict refs" in use” .i think this error because of “foreach my $sql ($query->{content}) {” loop on line no 42. Can you suggest some way solve this??

Thank you very much

PERL Script

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use SQLValidation; use XML::Simple; my $xml_obj1 = XML::Simple->new(); #my $file_path = 'C:\Users\Desktop\sql_test.xml' ; my $file_path = 'C:\Users\Desktop\derived_tif_cd.XML' ; my $xmlfile = $xml_obj1->XMLin($file_path) or die "Failed for $f +ile_path: $!"; #print Dumper $xmlfile; =c my $val = $xmlfile->{queries}->{query}->[2]->{content}; print "$val"; =cut foreach my $queries ($xmlfile->{queries}){ if($xmlfile->{queries} eq 'query') { foreach my $query (@{$queries->{query}}) { foreach my $sql ($query->{content}) { print "$sql\n"; } } } else { foreach my $query (@{$queries->{query}}) { print "---->$query\n"; } } }

XML Data File


<Common_Checks> <comments> This xml includes validations for order event types (C +hecks for Others). </comments> <queries> <comments> ORDER_TYPE_CODE and expiration date for TIF code derivati +on: </comments> <query> INSERT INTO table_name (column1, column2, colum +n3,...) select (value1, value2, value3,...); <orderTypes>order_nw_stgng</orderTypes> <orderTypes>order_or_stgng</orderTypes> <orderTypes>order_oe_stgng</orderTypes> <orderTypes>order_cr_stgng</orderTypes> <queryParam>BATCH_ID</queryParam> </query> <query> GENERATE EXPRESS STATISTICS ON drvd_tif_order_stgng +; </query> <comments> ORDER_TYPE_CODE and expiration date for TIF code derivati +on: </comments> <query> INSERT INTO table_name (column1, column2, column3,...) s +elect (value1, value2, value3,...); <orderTypes>order_nw_stgng</orderTypes> <orderTypes>order_or_stgng</orderTypes> <orderTypes>order_oe_stgng</orderTypes> <orderTypes>order_cr_stgng</orderTypes> <queryParam>BATCH_ID</queryParam> </query> <query> GENERATE EXPRESS STATISTICS ON drvd_tif_order_stgng; </query> </queries> </Common_Checks>

In reply to problem on xml parsing with xml::Simple module by sarf13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.