When Perl golfing, I like to try out new ideas and want to know quickly how they score. But I also like to have readable code while I'm writing it. So I keep a nice, readable working copy of my code and use this script to "golfify" and test my code quickly. This script has hard-coded filenames to work for TPR(0,4), which is currently in progress, but you can easily modify it or even pass the filenames from the command line. It's quick and dirty, so the files need to be in the current directory, etc.
#!/usr/local/bin/perl use warnings; use strict; my $working_file = 'interlin-working.pl'; my $golfy_file = 'interlin.pl'; my $test_script = 'tpr04.pl'; # Read source file, keeping shebang line separate open IN, "<$working_file"; my $header = <IN>; local $/ = undef; my $text = <IN>; close IN; # Remove comment lines, newlines, space at beginning of lines $text =~ s/\n\s*(\#[^\n]*)?//g; # Convert \n and \t to literal newline, tab $text =~ s/\\n/\n/g; $text =~ s/\\t/\t/g; # Write the golfified program and run it through the golf test script open OUT, ">$golfy_file"; print OUT $header, $text; close OUT; system("perl $test_script");