sarf13 has asked for the wisdom of the Perl Monks concerning the following question:
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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem on xml parsing with xml::Simple module
by tobyink (Canon) on Aug 07, 2012 at 12:18 UTC |