Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: read a file and insert closing tags if not present

by gopalr (Priest)
on Mar 29, 2007 at 10:36 UTC ( [id://607196] : note . print w/replies, xml ) Need Help??


in reply to read a file and insert closing tags if not present

Hi Valavan,

my $sgml = <<SGML; <html> <greeting class="simple">Hello, world!<head>heading</head> </html> SGML while ($sgml=~s#(<)([^/<>\s]+)((?:\s[^/<>]+)?>)([^<>]+)(<[^/<>]+>)#$1$ +2$3$4$1\/$2>$5#){} print "\n\n"; print "\nOutput:\n$sgml\n"; print "\n\n";

Input:

<html> <greeting class="simple">Hello, world!<head>heading</head> </html>

Output:

<html> <greeting class="simple">Hello, world!</greeting><head>heading</head> </html>
~ ~ ~ ~ ~