Base 64 encoding + decoding
perl -MMIME::Base64 -e 'print encode_base64("text");'
List all installed Perl modules and its version
perl -MExtUtils::Installed -e '$m=ExtUtils::Installed->new(); \
for($m->modules()){my$v=$m->version($_)||"-"; printf("%-10s %-50s\n",$v,$_);}'
Sum up a column of a csv file and skip header
perl -a -F";" -ne 'BEGIN {<>} $a+=$F[5]; END {print $a,"\n";}' csvfile
Sucking in a file
including error handler and comments
@arr = ();
$fn = "/some/where/filename";
open(F,$fn) or die("cannot open '$fn': $!\n");
while(<F>) {
chomp;
s/^\s*(.*?)\s*(#.*)?$/$1/;
if ($_ eq "") {
next;
}
push(@arr,$_);
}
close(F);
Reading a configfile
with removing white space and '#'-comments
while (<>) {
chomp;
s/^\s*(.*?)\s*(#.*)?/$1/;
next if ($_ eq "");
($key,$value) = split(/\s*=\s*/);
$conf{$key} = $value;
}