#!/usr/bin/perl # For debug purposes, set ONE debug value to 1 instead of 0. NEWLINE can be "\n" for unix/macos or "\r\n" for windows. # Shows steps which don't match any characters. Currently, we look for previous step and assign these to any characters matched by the prior step. $DEBUG_NOMATCH = 0; # Shows steps which match multiple characters. $DEBUG_MULTIMATCH = 0; # Shows steps don't directly match any characters, but prior step matches multiple. $DEBUG_NOMATCH_MULTI = 0; # Shows steps don't directly match any characters, and we fail to find prior characters. This probably shouldn't happen. $DEBUG_NOMATCH_NONE = 0; $NEWLINE = "\r\n"; # Not intended for modification $STEP_COUNT = 0; $DEBUG_COUNT = 0; @women = ("Janice", "Julia", "Billy", "Kelly", "Emma", "John", "Rebecca", "Adrianna", "Rachel", "Danielle", "Kira", "Kendra", "Michelle" ); foreach $w ( @women ) { $w_steps{$w} = ""; } $w_steps{"nomatch"} = ""; # Takes a step, finds it's step #, and looks through each character to find the prior step. Adds current step to any character matching the prior step. sub find_last_match { my $step = shift(@_); my $stepnum = 0; my $nomatch_match = 0; if ($step =~ m/^\s*(\d+)\.\s+/) { $stepnum = ($1 - 1); foreach $w (@women) { #print "Checking nomatch step $stepnum in woman $w\n"; if ( $w_steps{$w} =~ m/^$stepnum\.\s+/m ) { # print "NOMATCH step " . ($stepnum + 1) . " matched $w\n"; $nomatch_match++; $w_steps{$w} .= $step; } } } else { print "BAD: Failed to find step number in $step\n\n"; return; } if ( $DEBUG_NOMATCH_NONE && $nomatch_match == 0 ) { print "NOMATCH_NONE for step " . ($stepnum + 1) . $NEWLINE . $step; $DEBUG_COUNT++; } elsif ($DEBUG_NOMATCH_MULTI && $nomatch_match > 1 ) { print "STEP NOMATCH_MULTI: $step"; $DEBUG_COUNT++; } } # Takes a step, and adds it to each character matched in the text. sub assignstep { my $step = shift(@_); my $w_matched = 0; my $w_nomatch = ""; foreach $w ( @women ) { if ($step =~ m/$w/ ) { $w_steps{$w} .= $step; $w_matched++; } } if ( $w_matched == 0 ) { # Find last character matched in prior step, and assign this step to that character(s) find_last_match( $step ); $w_steps{"nomatch"} .= $step; if ($DEBUG_NOMATCH) { $DEBUG_COUNT++; print "STEP NOMATCH: $step"; } } if ( $DEBUG_MULTIMATCH && $w_matched > 1 ) { $DEBUG_COUNT++; print "STEP MULTMATCH: $step"; } } open(F, "<", $ARGV[0]); $step = "x"; $steptext = ""; $past_intro = 0; $intro = ""; while ($line = ) { if ($past_intro == 0 && $line !=~ m/\(9\)\s+Walkthrough/) { $intro .= $line; } if ($line =~ m/\(9\)\s+Walkthrough/) { $past_intro = 1; } next if ($past_intro == 0); next if ($line =~ m/^\-+/ ); next if ($line =~ m/^\s*$/ ); next if ( $line =~ m/^\s*([\d\.]+)\s+/ && $1 < 1.0); if ( $line =~ m/^\s*([\d]+)\.\s+/) { if ( $step != "x" && $step != $1 ) { assignstep( $steptext ); $STEP_COUNT++; } $step = $1; $steptext = $line; } else { $steptext .= $line; } } close(F); if ( $DEBUG_NOMATCH || $DEBUG_MULTIMATCH || $DEBUG_NOMATCH_MULTI || $DEBUG_NOMATCH_NONE) { print "Debugged steps: $DEBUG_COUNT" . $NEWLINE; exit; } #push( @women,"nomatch" ); print $intro; foreach $w ( @women ) { print "$w Path:" . $NEWLINE; print "=" x length($w) . "======" . $NEWLINE; print $w_steps{$w}; print $NEWLINE x 2; }