Hi Monks,
I have an excel csv file which has 10000 records.
Each record will be like:
– &dash
Output CSV file should be:
'ߝ' => '‐'
I converted the xls file into xml. Than i used the below code to do the task:
use strict;
use warnings;
use XML::Twig;
#open(FH, "conv.xml");
my $file="C:/conv.xml";
my $tmp;
$tmp = XML::Twig->new();
$tmp->parsefile($file);
my $root = $tmp->root;
my $hex_value;
my $entity_value;
my $real_value;
#while (<FH>){
open(FH, ">records.txt");
foreach my $record ($root->children('record')){
if ($record->first_child_text('hex_value') eq '') {
$hex_value='';
}else{
$hex_value = $record->first_child_text('hex_value');
$hex_value=~s/^\s*//g;
}
if ($record->first_child_text('entity_value') eq '') {
$entity_value='';
}else{
$entity_value = $record->first_child_text('entity_value');
$entity_value=~s/\s*$//g;
}
if ($record->first_child_text('real_value') eq '') {
$real_value=$entity_value.";";
}
#print "$real_value\n";
#print FH "Hexadecimal Value \t Entity Value \t Real_value";
print FH "\'$real_value\' => \'$hex_value\'
+,\n";
}
I think the above code is not efficient. Can anyone suggest me efficient one to do that.
Thanks all monks for your suggestion.