1. Install CPAN module without system privilege:
Install the moduel to /app/dvsynhk/apps/perl/
tar -zxvf Spreadsheet-Read-0.46.tgz
cd Spreadsheet-Read-0.46
perl Makefile.PL PREFIX=/app/dvsynhk/apps/perl/
make
make test
make install
Use the installed module:
#!/usr/bin/perl -w
use strict;
use lib '/app/dvsynhk/apps/perl/lib/perl5/site_perl/5.8.8/';
use Spreadsheet::Read;
2. Files can be renamed, so that they can be correctly sorted by filename:
#/bin/perl
# this program rename any file with [0-9]+.jpg to [0000].jpg
# apply recusively to sub folders
use Cwd;
use File::Find;
use File::Basename;
$type = "jpg";
$path = &Cwd::cwd();
opendir(DIR, "$path");
@FILES = ();
&File::Find::find( sub {push @allFiles, $File::Find::name;}, ".");
foreach $file (@allFiles) {
if ( $file =~ "[0-9]+\.$type") {
$folder = dirname($file);
$basename = basename($file,(".$type"));
$newname = sprintf("%04d",$basename);
print "$file --> $basename --> $folder/$newname.$type\n";
rename($file, "$folder/$newname.$type");
}
}
3. Reference and dereference
http://www.perlmeme.org/howtos/using_perl/dereferencing.html
#!/usr/bin/perl
use strict;
use warnings;
my $scalar = "This is a scalar";
my $scalar_ref = \$scalar;
print "Reference: " . $scalar_ref . "\n";
print "Dereferenced: " . $$scalar_ref . "\n";
4. Sort Hash table, by key or by value
http://www.tizag.com/perlT/perlhashes.php
5. Regex to match YYYYMMDD
if ( defined($opt_t) &&
$opt_t =~ m/^(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$/ ) {
($g_year, $g_mon, $g_mday) = (substr($opt_t, 0, 4), substr($opt_t, 4, 2), substr($opt_t, 6, 2) );
} else {
printf "-t option found with a invalid date string ($opt_t).\n";
exit 1;
}
6. Call external commands
http://www.perlhowto.com/executing_external_commands
7. De-compile (unzip) the .exe file packed by PerlApp
http://www.perlmonks.org/bare/?node_id=394546