Archive for the 'Perl' Category

Installing Perl Modules

Install Perl modules on a linux system - must be connected to the net

perl -MCPAN -e shell

If CPAN is not installed use this command to install it in a RedHat/Fedora system.

yum install perl-CPAN

If you are doing this for the first time, there will be a configuration procedure.

install XML::Parser

Some recommended Modules

DBI
DBD::mysql
MIME::Lite
MIME::Words
Compress::Zlib
MIME::Base64
URI::URL
HTML::Tagset
HTML::Parser
LWP::Simple
GD
RPC::XML
SOAP::Lite
XML::RSS

Command to Replace a String in all Files in Current Directory

Replaces all instance of ‘<old string>’ with ‘<new sting>’ in all the files of the current directory.

perl -pi -e "s/<old string>/<new string>/g;" *

[tags]perl,command,rename,replace,string[/tags]

Changing separator with Perl

This will join all lines of a file together. Sometimes I have a list of something in a file, one line per item and want to convert it to a comma(colon,tab)-separated line (with no trailing separator of course) that can be used as a command-line parameter to some other tool.


perl -e '@_=; chomp(@_); print join(";",@_);' < data_file