http://www.perlmonks.org?node_id=607196


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>
~ ~ ~ ~ ~