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>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.