People bad. Fire pretty. (cdybedahl) wrote in perl,
People bad. Fire pretty.
cdybedahl
perl

  • Music:

In case you wondered

A string of eighty randomly chosen printable ASCII characters is about 4.6% likely to be compilable Perl.

#!/usr/bin/perl -l

close STDERR;			# To avoid all the compilation error messages

our $broken = 0;
our $works = 0;
our $count = 100_000;

for (1..$count) {
    $str = pack("c*", map {32+rand(95)} 1..80);
    eval $str;
    if ($@) {
	$broken++
    } else {
	$works++
    }
}

printf "Score: %0.1f%% non-working entries, %0.1f%% working ones.\n",
  100*$broken/$count,
  100*$works/$count;

      
  • Post a new comment

    Error

    default userpic
  • 11 comments