#!/usr/bin/perl -w
# Based on http://www.hadess.net/files/stuff/vpenis.c
# But I made it logarithmic.

# Currently only for linux

use strict;

my $uptime	= "uptime";
my $free	= "free";
my $df		= "df";
my $cpu_info	= "/proc/cpuinfo";

my $size = 0;

my @uptime = `uptime` or die "Could not run $uptime\n";
for (@uptime) {
    $size += $1 / 10 if /(\d+) day/;
}

open(my $fh, "<", $cpu_info) || die "Could not open $cpu_info: $!";
while (<$fh>) {
    $size += $1 / 30 if /cpu MHz.*:\s+(\d+(?:\.\d+)?)/i;
}

my @free = `free` or die "Could not run $free\n";
for (@free) {
    $size += $1 / 1024 / 3 if /^Mem\S*\s+\S+\s+(\d+)/i;
}

my @df = `df -P -k -x nfs` or die "Could not run $df\n";
shift @df;
for (@df) {
    my ($fs, $blocks) = split;
    $blocks *= 2 if $fs =~ m!/scsi|/sd!;
    $size += $blocks/1024/750;
}

# my $result = 7+$size/10;	# Original formula
my $result = 7+2*log(1+$size);
printf "Your virtual penis size is %.1f centimeters (%.1f inch)\n", $result, $result / 2.54;
