Title G: #givens Given 1 Given 2 etc. P: proof statement Pr: #start of proof statement 1 => reason 1 etc. #### #!/usr/bin/perl -w use strict; my ($file, $tr, @s, @r, $len, $lent, $pad, $i, $line); $file="untitled:Desktop Folder:test2"; open (HAN, "<$file") or die ("Can't open $file: $!\n"); $tr=0; #I used $tr so I could skip the if statement in the while loop W ##### # Start a loop to go through the file to be parsed ##### W: while () { chomp; if ($_ ne "Pr:" and $tr == 0) { #Just print out the Givens and the Prove statement, "Pr:" appears before the actual proof print $_ . "\n"; next W; } elsif ($tr == 0) { print "\n\n"; $tr=1; next W; } m/(.+) => (.+)/; #format is statement => reason push @s, $1; #constuct an array of statements push @r, $2; #constuct an array of reasons } close (HAN); $len=0; $lent=0; ##### # Find the longest statement and reason for formatting ##### foreach (@s) { if ( $len < length() ) { $len = length(); } } foreach (@r) { if ( $lent < length() ) { $lent = length(); } } $pad=length($#s+1); #This is so the numbers along the side are lined up correctly print "_" x ($len+$pad+4) . "|" . "_" x ($lent+2) . "\n"; #Print the top ie _____|______ for ($i=0; $i<$#s+1; $i++) { $r[$i] =~ s/#-(\d+?)/($i+1)-$1/ge; #replace #-? with the line # you are on minus ? print $i+1 . "." . " " x ($pad - length($i+1)+1) . $s[$i] . " " x ($len - length($s[$i])) . " | " . $r[$i] . "\n"; #print the statements and resons }