Tuesday, September 22, 2009

my perl-fu is weak =/

ok, it's been a LOOOONG time since I've had to uhm, I mean the opportunity to work in perl. This will be my catchall post for useful stuff...

For example:

The special $/ which can be used to slurp an entire file at once if you don't really need to loop over the lines.

sub getfile {
my $filename = shift;
open HANDLE, "< $filename" or die "Couldn't open `$filename': $!";
local $/ = undef; # Read entire file at once
$contents = <HANDLE>; # Return file as one single `line'
close HANDLE;
return $contents;
}