Now I can get back to the ToCS assignment...
-----
#!/usr/local/bin/perl
$/="";
$indent = 1;
$spaces="";
$_ = <>;
# all this is to hide "(" and ")" and then put them back after we set the
# points where we are going to split
s/\n/ /g;
s/\"\(\"/\[/g;
s/\"\)\"/\]/g;
s/\(/\&\(/g;
s/\)/\&\)/g;
s/\[/\"\(\"/g;
s/\]/\"\)\"/g;
@nospam.bits = split(/\&/);
foreach $line (@nospam.bits) {
if ( $line =~ /^\(/ ) {
print "$spaces$line\n";
$spaces = " " x $indent++;
}
elsif ( $line =~ /^\)/ ) {
$spaces = " " x (--$indent - 1);
print "$spaces$line\n";
}
else {
print "$spaces$line\n";
}
}