Thursday, November 26, 2009

Earning rebates when shopping online in Canada

As someone that enjoys shopping for things online, I thought that I would share a way for Canadian shoppers to earn rebates while shopping for items online.

Great Canadian Rebates is a site that lists various online retailers and offers coupons/rebates (ranging from a flat amount of cash back, to 12%) on items that you buy from retailers that they list. The require you to sign up for an account and then to click through their site to shop the online retailer. With my account, I have received just under $70 back in under a year. They even give you a toonie ($2) for just signing up!

I figure that since I buy stuff online, why not get a little something back!

Wednesday, November 25, 2009

Perl script to exact packages from multi package Perl module

Here is a little script that I use to extract the individual modules from a multiple package Perl module.

While the script works, it isn't perfect and if you have any comments, have an addendum, etc, please let me know!

The script is below. Please make sure to edit $file, the input file, and $outdir, the destination directory. Good Luck.

#!/usr/bin/perl -w
use strict;
use File::Spec;
use File::Path qw(mkpath);
my $file = '/exact/path/to/perl/module.pm';
my $outdir = '/tmp/';
open(my $fh, '<', "$file") or die $!;
my $contents = '';
my $filename = undef;
while (<$fh>) {
if ( $_ =~ /^package (.*);/g ) {

# construct a new file
$contents = '';

# its filename
$filename = File::Spec->catfile( $outdir, split( /::/, $1 ) ) . '.pm';

# its contents
$contents .= $_;
} elsif ( $_ =~ /^1;/g ) {

# put the contents into $filename
$contents .= $_;
my ( $volume, $directories, $file ) = File::Spec->splitpath($filename);

# make the path
mkpath(
$directories,
{
verbose => 1,
mode => 0711,
}
);
do {
open OUT, ">$filename" or die "Can't write to $filename: $!\n";
print OUT $contents;
close OUT;
} if $filename;
} else {
$contents .= $_;
}
}
close $fh;