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");
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.