#input file name subname start size CAL_M reserved 0 13 CAL_M o_check_out 13 7 CAL_M o_ttr_first 20 4 CAL_M o_cal_check_1 24 4 PSQN_0 reserved 0 8 PSQN_0 check_final 8 10 PSQN_0 o_check 18 10
#expected output file <structure name="CAL_M"> <value type = "13"name = "reserved" start = "0" </value> <value type = "7" name = "o_check_out" start = "13"</value> <value type = "4" name = "o_ttr_first" start = "20"</value> <value type = "4" name = "o_cal_check_1"start = "24"</value> </structure> <structure name="PSQN_0"> <value type = "8" name = "reserved" start = "0" </value> <value type = "10" name = "check_final"start = "8"</value> <value type = "10" name = "o_check" start = "18" </value> </structure>
Here's my code#current output file <value type = "13"name = "reserved" start = "0" </value> <value type = "7" name = "o_check_out" start = "13"</value> <value type = "4" name = "o_ttr_first" start = "20"</value> <value type = "4" name = "o_cal_check_1"start = "24"</value> <value type = "8" name = "reserved" start = "0" </value> <value type = "10" name = "check_final"start = "8"</value> <value type = "10" name = "o_check" start = "18" </value>
#input file open (FILE,"<in.csv") || die "cannot open file: $!"; my @array =<FILE>; close (FILE); #output file my $output_file = "myfile.xml"; my $output = new IO::File(">$output_file"); my $writer = new XML::Writer(OUTPUT=>$output, DATA_MODE=>1, DATA_INDEN +T => 2); #structure foreach my $item(@array) { chomp($item); $item =~/(\w+),(\w+),(\d+),(\d+)/; my $name =$1; my $sname=$2; my $start=$3; my $size =$4; $writer->startTag("structure", "name"=>$name); $writer->startTag("value", "type"=>$size, "name"=>$sname, "start"= +>$start); $writer->endTag(); $writer->endTag(); } $writer->end(); $output->close();
In reply to perl writing to xml file (xml::writer) by analys
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |