# codeformat.pl # # CubicSpline # 2001/10/13 # # Purpose: Format perl source file in a particular shape. # # Run: perl codeformat.pl use strict; use warnings; # SOURCE reads in the perl source code open SOURCE, $ARGV[0]; # PATTERN reads in the format text file open PATTERN, $ARGV[1]; # make a single string that contains entire source my $sourceline = join '', ; # strip out newlines and tabs and create character array, # reversed for popping. $sourceline =~ s/\n|\t//g; my @sourcechars = reverse split //,$sourceline; close SOURCE; my $output = ""; my $i; # read in pattern file line by line # for every non-space (ASCII 32) character # output the next char of the source string. while( ) { chomp; my @patternchars = split //; for( $i = 0; $i <= $#patternchars;$i++) { $output .= $patternchars[$i] eq " " ? " " : pop @sourcechars; } $output .= "\n"; } close PATTERN; # print out the formatted source and any remaining # source that didn't fit into the pattern. print $output; if( scalar(@sourcechars) > 0 ) { print "\n\n",scalar(@sourcechars)," Remaining: \n\n", reverse @sourcechars; }