Posts Tagged Perl

LCOD – 4.12.10 – Quick Mysqlreport to e-mail setup

This will be a quick install to setup your server to e-mail you daily mysql reports using the cool mysqlreport application at hackmysql.com

Click to continue reading “LCOD – 4.12.10 – Quick Mysqlreport to e-mail setup”

, , , , , , , ,

No Comments

LCOD – 5.9.07 – Updating CPAN in Perl

Perl rocks, it’s easily my favorite programming language. One of the nice things about Perl is the CPAN (Comprehensive Perl Archive Network). Your Linux box has CPAN installed already, and to begin using it you should first update it. To do so run the commands just below. The first time you invoke CPAN it’ll launch the configuration module, just hit enter until it gets into the part about which mirrors you want to use, it’ll have you pick geographic areas first, and then tell you to enter servers by number, separated by spaces. I usually put in about 20 servers, which looks like kinda this

30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10

#invoke perl’s CPAN shell (and first time configuration with)
bash$ perl -MCPAN -e shell
#once configuration is done, update CPAN, and then reload
CPAN> install Bundle::CPAN
CPAN> reload cpan

Now, head on over to CPAN and search for some cool new Perl modules to play with!

A great place to dive into the world of Perl is Perl.org

Also the Perl Monks is a good Perl site, and Use Perl is as well.

Make sure you have a correct build environment setup, on Ubuntu/Debian you need to install the build-essential package (sudo apt-get install build-essential)

, , , ,

No Comments

LCOD – 5.9.07 – Find out what Perl DBI drivers are installed

A perl one liner for you.

Say you’re installing something that is DBI and it’s giving errors or having problems,

or anything, and you want to know if it’s because you don’t have the correct perl DBI

driver installed? This is a simple, one liner, which will tell you a list of all the perl DBI drivers.

Run from the command line

perl -e ‘use DBI;@driver_names = DBI->available_drivers; print “@driver_names\n”;’

You should get output like

DBM ExampleP File Proxy SQLite2 Sponge mysql

enjoy

, , ,

No Comments

LCOD – 2.18.07 – Simple command line perl substitutions

Ever have a list of things that you want to change all the same? Say you have an image directory and you want to make an html list of all the images in your directory? Perl to the rescue!

first, make a file that lists all the images (we’re using *jpg, but you could do *gif, or *coolimages*, or just * for all files in the dir – note: all files in dir * with a redirect will catch the file you are redirecting to, and it will likely need to be removed)

From the shell / command line, run:

/bin/ls *jpg > ourfiles

Now the fun part! This will take a line like this

picture1.jpg

And make it look like this
<a href=”picture1.jpg”><img src=”picture1.jpg” border=”0″></a>

From the shell run / command line, run:

perl -pi -e ‘s/^(.*)$/<a href=\”$1\”><img src=\”picture1.jpg\” border=\”0\”><\/a>/’ ourfiles

The basic pattern of this command is

‘s/SEARCH PATTERN REGEX/REPLACEMENT PATTERN/’

The search pattern is a Regular Expression, and the Replacement Pattern needs to have any special characters escaped (including / $ # @ “) with a \

The Search Pattern we’re using is a simple one ^ for start of line, (.*) for . anything and * any number of times, with paranthesis around it to put it into the perl variable $1, and $ for end of line.

, , , , ,

No Comments

Easy AdSense by Unreal