Sunday, April 8, 2012

Perl programming


Perl programming?
Sample Data: <tocelement name="New classification and <tocelement name="Gestational diabetes mellitus <tocelement name="Glycohaemoglobin: a 1997" ca= "ANZ" <tocelement name="The prevention <tocelement name="Diabetes and </tocdivision> Program: while (<TEMP1>) { $CountTB=substr $_,0,1; print $CountTB; if ($CountTB eq "<") { print TEMP2 $_; } else { print "OK"; print "\b", TEMP2 $_; } } Problem: I want the " 1997......" to be in 1 line before it. Meaning all lines must first start with "<" since the file is an xml. how am i gonna do it. i have a sample program but everytime i ran it, it stops at the sntence " 1997......" please help???? Correct output i want: <tocelement name="New classification and <tocelement name="Gestational diabetes mellitus <tocelement name="Glycohaemoglobin: a 1997" ca= "ANZ" <tocelement name="The prevention <tocelement name="Diabetes and </tocdivision>
Programming & Design - 2 Answers
Random Answers, Critics, Comments, Opinions :
1 :
I only dredge up Perl when I need a quick and dirty solution so I can't claim to be an expert. But have you looked for XMLWriter in CPAN? Module ref in link below...
2 :
Can you just delete all \n when not immediately followed by < ? undef $/; my $sAll = <TEMP1>; $sAll =~ s/\n([^<])/$1/g; print TEMP2 $sAll;







 Read more discussions :