Perl Tips PDF
Wednesday, 18 July 2007

Tip1. Perl script to remove ^M characters


while (<>) {
$_ =~ s/\cM\n/\n/g;
print $_;

This will output to stdout the content of file given as parameter. Save it to and use it: source.txt > dest.txt

Tip 2. Show servers's environment variables: $ENV

#!/usr/bin/perl -w

use strict;

print "Content-type: text/html\n\n";

print "<html><body><table>";

foreach (sort keys %ENV) {

    print "<tr><td>$_</td><td>$ENV{$_}</td></tr>\n";


print "</body></html>";

Tip. 3 Install a Perl module from CPAN. (Example for module Mail::Mailer)

You know howto install a perl module by adding a FreeBSD package for that module or by building the module from ports, but how if you want to automatically install a Perl module from CPAN. Well, Perl has the feature to automatically install any module from CPAN by using the following line:

perl -MCPAN -e "install Mail::Mailer"

This will install Mail::Mailer to your system.

Last Updated ( Wednesday, 01 August 2007 )

Other BSD Systems





Best BSD firewall?