max has asked for the wisdom of the Perl Monks concerning the following question:
Here is my input looks likeuse File::Glob ':glob'; #use File::DosGlob qw( glob ); use XML::Simple; use File::stat; use Time::localtime; $Sortline="C:\\Documents and Settings\\1-test.xml"; $Header="C:\\Documents and Settings\\header.txt"; $Detail="C:\\Documents and Settings\\detail.txt"; open(MYHEADERFILE, ">>$header"); open(MYDETAILFILE, ">>$detail"); my $date = localtime( (stat HANDLE)[9] ); $position = rindex($Sortline, "/")+1; $workorderfilename = substr($Sortline, $position); $pos = index($workorderfilename,'-'); $workorder = substr($workorderfilename,0,$pos); $datetime_string = ctime(stat($Sortline)->mtime); $xml = new XML::Simple; $data = $xml->XMLin($Sortline); $rows= "$data->{table}->{nrows}"; $i=0; for(my $i=0;$i<$rows;$i++) { print MYDETAILFILE "$workorderfilename,$workorder,$data->{table}->{stake_report}->[$i]->{ +struc_num},$data->{table}->{stake_report}->[$i]->{stock},$data->{tabl +e}->{stake_report}->[$i]->{quantity}\n"; } print MYHEADERFILE "$workorderfilename,$workorder,$data->{creator}->{project},$data->{cre +ator}->{projectpath},$datetime_string\n"; #printf MYOUTPUTFILE "$Sortline\n"; close MYOUTPUTFILE; close MYHEADERFILE; close MYDETAILFILE;
<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <!-- Created by CADD Version 9.23 on 9:55:05 AM 1/22/2009 by MAX --> <root> <creator application='PLSCADD' version='Version 9.23' registereduser=' +MAX' date='1/22/2009' time='9:55:05 AM' computer='XXX' user='YYY' pro +ject='test.xyz' projectpath='y:\temp folder\test.xyz' activeline='' p +lsxmlver='1.0'/> <table plsname='Stake Report' tagname='stake_report' ncols='14' nrows= +'13' units='0' titledetail=''> <stake_report rownum='0'> <struc_num>15.0</struc_num> <stock>H1ST_556</stock> <description>*** UNDEFINED PART ***</description> <quantity>1.00</quantity> </stake_report> <stake_report rownum='1'> <struc_numr> </struc_num> <stock>SP4/100</stock> <description>*** UNDEFINED PART ***</description> <quantity>2.00</quantity> </stake_report>
Here is my output
C:\Documents and Settings\1-test.xml,1,15.0,TEST_556,1.00
C:\Documents and Settings\1-test.xml,1,HASH(0x1b635c4),SP4/100,2.00
I need output like this if there is no data in the xml file for a required column
C:\Documents and Settings\1-test.xml,1,,SP4/100,2.00
I have tried using Dumper,hash but not able to make it successfully to get output.I am not sure whether I have to use different xml module for this xml file structure. can someone help how to resolve this?Any inputs or directions are highly appreciated. Thanks, Ruth
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: writing null/empty data as "HASH(0x1b635c4)" ,xml file
by ikegami (Patriarch) on May 21, 2009 at 04:05 UTC |