in reply to Indenting XML
# assume that the long string from XML::Simple is assigned to $_: s/></>\n</g; # put line breaks between all adjacent tags my @lines = split( /\n/ ); my $indent = 0; $_ = ""; foreach my $l ( @lines ) { $indent -=2 if ( $l =~ /<\// ); # close tag decreases indent $_ .= " " x $indent . "$l\n"; $indent +=2 if ( $l =~ /^<\w/ ); # open tag increases indent } print;
|
|---|