#!/usr/bin/perl use strict; sub GolfScore { my $script = shift; local ($_, *FF); open(FF, $script) or die "could not open $script: $!"; my $golf = -1; # your free last newline while () { s/\n?$/\n/; $golf-- if $. == 1 && s/^#!.*?perl//; $golf += length; } close(FF); return $golf; } my $script = shift; print "You shot a round of ", GolfScore($script), " strokes\n"; my $a; $a = `perl $script 1 2>err`; -s "err" and die "oops, you wrote to STDERR\n"; $a = `perl $script A0 2>err`; -s "err" and die "oops, you wrote to STDERR\n"; $a ne "360\n" and die "expected:\n--\n360\n--\ngot:\n--\n$a"."--\n"; $a = `perl $script 1B 2>err`; -s "err" and die "oops, you wrote to STDERR\n"; $a ne "47\n" and die "expected:\n--\n47\n--got:\n--\n$a"."--\n"; $a = `perl $script ZZZ 2>err`; -s "err" and die "oops, you wrote to STDERR\n"; $a ne "46655\n" and die "expected:\n--\n46655\n--\ngot:\n--\n$a"."--\n"; print "Hooray, you passed!\n";