in reply to Perl Purity Test (For Update)
I wrote this script to play the above purity test:
#!/usr/bin/perl -w use strict; use Term::ReadKey; my %answer; while(<DATA>) { if (/^\.\.\./) { chomp; print "$_ (y/n)"; my $ans = ''; ReadMode('cbreak'); $ans = ReadKey(0) while ($ans ne 'y' and $ans ne 'n'); print "$ans\n"; ReadMode('normal'); $answer{$ans}++; $answer{t}++; } else { print; } } my $py = $answer{y} / $answer{t} * 100; my $pn = $answer{n} / $answer{t} * 100; print <<"EOF"; Results: You answered: $answer{y} 'yes' ($py %) $answer{n} 'no' ($pn %) EOF __DATA__
(Copy and paste the purity test after __DATA__)
|
|---|