subs.pl // Subroutines

This is what I have, two hours in. This code has been adapted from some previous code I’ve written.
#Subroutines
sub epoch_to_datef{
		##requires use Time::gmtime; in header
	($seconds, $minutes, $hours, $day_of_month, $month, $year, $wday, $yday, $isdst) = localtime($results[6]);
	if (length $minutes == 1){
		$minutes = sprintf("%02d", $minutes);
		$minutes=~ tr/ /0/;
	}
	if (length $month == 1){
		$month = sprintf("%02d", $month);
		$month=~ tr/ /0/;
	}
	if (length $day_of_month == 1){
		$day_of_month = sprintf("%02d", $day_of_month);
		$day_of_month=~ tr/ /0/;
	}
	$hours += 4;
	if (length $hours == 1){
		$hours = sprintf("%02d", $hours);
		$hours=~ tr/ /0/;
	}

	$year+=1900;
	$Month++;
	$dt = $hours . ":" . $minutes . " " . $day_of_month . "/" . $month . "/" . $year;
	return $dt;
}
sub printHeader {
	$_ = shift;

	"Content-type: text/html\n\n";
	print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
			\"http://www.w3.org/TR/html4/loose.dtd\">

		<html lang=\"en\">

		<head>
			<link rel=stylesheet href=\"Perl.css\" type=\"text/css\">
			<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
			<title>Uploadr | $_ </title>
		</head>
		<body>
		<h2>$_</h2>";
}

sub printFooter {
		##requires use Time::HiRes qw(gettimeofday tv_intverval); in header
	$t1 = [gettimeofday];
	$time = tv_interval($t0,$t1);
	print "<p class=\"sm\">This page was generated in <b>" . $time . "</b> seconds.</p>
	</body>
	</html>";
}
sub randomPassword {#from paulbradley.tv/30

my $password;
my $_rand;

my $password_length = $_[0];
    if (!$password_length) {
        $password_length = 10;
    }

my @chars = split(" ",
    "a b c d e f g h i j k l m n o
    p q r s t u v w x y z
    0 1 2 3 4 5 6 7 8 9");

srand;

for (my $i=0; $i <= $password_length ;$i++) {
    $_rand = int(rand 41);
    $password .= $chars[$_rand];
}
return $password;
}

sub connectDB{
	require "vars.pl";
	my $dbh = DBI->connect($dsn, $username, $password) or die "couldn't make DBH: " . $dbh->errstr;
	undef $db_usr, $db_pswd, $dsn, $database;
}
sub setMessage{
	$_ = shift;

	if($_ == 1){
			##noname and thensome
		return "<p>There are many things that may have gone wrong with this file upload:
		<ol>
		<li>There is a file-size limit of <hilite>10MB</hilite> per file. (That's <hilite>10*(1024^3)</hilite>)</li>
		<li>You may have forgot to select a file in the previous page as the filename that came through was <hilite>$filename</hilite>.</li>
		<li>Something may have gone wrong with the internet connection.</li>
		<li>You're browser may have messed something up (especially if you're using IE!)</li>
		<li>These fine-ass servers at Dreamhost may have failed you and ME.</li>
		<li>It may be possible that this script failed.  Just maybe.  ;P</li>
		</ol>
		</p>
		<p>Hope this helps!</p>
		<p>With Love,<br />Brad</p>";

	}elsif($_ == 2){
			##Short code timeout
		return "<p>There was one thing that happened to make this fail this time:
		<ol>
		<li>Imma level with you: I use a script to come up with a unique code to distinguish one file from another regardless of it's name, size, etc... And that times out after a number of tries, in this case it just ran <hilite>" . $x-1 . "</hilite> times.  So, to move on from here, just hit the refresh button in your browser OR <hilite>F5</hilite> or <hilite>CTRL-R</hilite> on Windows, <hilite>Command-R</hilite> on the Mac.  The Linux key command depends on the browser and distro.</li>
		</ol>
		</p>
		<p>Hope this helps!</p>
		<p>With Love,<br />Brad</p>";
	}elsif($_ == 3){
		return "<p></p>"
	} 	

}

sub Say{
	$_ = shift;
	return ("\n<p>$_</p><br />\n");
}
  • http://bradarsenault.com/post/2665 Days of Code: A Perl Uploadr // Day 1 « Brad Arsenault (dot com)

    [...] subs.pl // Subroutines [...]