William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Perl Padre IDE

Perl Padre IDE, Catalyst, and others

Perl is good at text processing, the following are some examples:

1. Add space between words
my $text = "ThisTextWithoutSpaces";
$text =~ s/([a-z])([A-Z])/$1 $2/g;
print $text; # This Text Without Spaces
2. Get the size of a file in bytes
$size = -s “path/to/file.txt”;

3.Running Windows? Got a file with UNIX line endings?
perl -ne "s/n/rn/; print;" linux.txt > windows.txt
# This changes 'n' to 'tn', like tr "n" "rn" 
4. Want to make a table of the number of times each word in $text appears?
my %words = ();
$words{lc($_)}++ for $text =~ /b([w']+)b/g;

Each key of the %words hash will be a word in $text, and the value is the number of times that word appeared.

5. Padre, the Perl IDE
Padre is a Perl IDE, an integrated development environment, the url is http://padre.perlide.org/.
After install Padre which also install Perl latest version (5.14), then install Catalyst, the Perl MVC framework:

$ cpanm Catalyst::Devel
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: