Wednesday, August 11, 2010

Env

Perl provides access to environment variables via the global "%ENV" hash. However, if using the ENV module, it will create global scalars for all the environment variables.
use Env;
print "$USER uses $SHELL";
If required to get only a few selected variables then it can be done like:
use Env qw[@PATH $USER];
print "$USER's path is @PATH";

FindBin

Its usage is like:
use FindBin;
use lib "$FindBin::Bin/../lib";

or

use FindBin qw($Bin);
use lib "$Bin/../lib";

Using hash for counting

When we have an array or a list of items and we want to find out the number of occurrences of a particular item then we generally use the following kind of logic:
 my $count = 0;
for (@list) {
$count++ if $_ eq "apple";
}
This can be made better by using the grep function like:
    $count = grep $_ eq "apple", @list;
Here we use the list returned by grep in a scalar context here by getting the number of elements in the grep -ed list.However if we have to find the count for more than one element in the list, then by this approach we need to make repetitive sentences like:
    $count_apples = grep $_ eq "apple", @list;
$count_pears = grep $_ eq "pear", @list;
A better method will be something like:
    my %histogram;
$histogram{$_}++ for @list;
This hash has a count of each individual item in the list and it also traverses the list only once.Moreover, to find number of unique elements in the list,all we have to do is:
    $unique = keys %histogram;
In order to find the five most popular items in the list we can do something like:
    @popular = (sort { $histogram{$b} <=> $histogram{$a} } keys %histogram)[0..4];
This sorts the unique elements of the list ie the keys of hash, in a descending order and pulls out only the top five.

Copying and Substituting Simultaneously

When the purpose is to search and replace a copy of the string and the intention is to accomplish this in one step then instead of doing this:
$dst = $src;
$dst =~ s/this/that/;
a single step like this will be more concise:
($dst = $src) =~ s/this/that/;

WebAPP

WebAPP is a popular, open source Content Management System (cms) written in the Perl programming language. The name WebAPP is an abbreviation of Web Automated Perl Portal. Available under the GNU General Public License, WebAPP is free software. Features Enhanced crypt, Articles, Forums and nested message boards, Private Instant Messaging system (IM), Who is Online, Profile info, Memberlist, sortable with links to IM, Profile and Email Download and Link sections, Stats with advanced sorting options, Webabsed Site Administration control panel, About, Contact and Help pages, Custom Welcome messages for guests and registered members. Languages The WebAPP script is available in these languages Afrikaans, Albanian, Bosnian, Brazilian Portuguese, Bulgarian, Catalan, Chinese (Simplified), Chinese (Traditional), Czech, Danish, Dutch, English, Estonian, Finnish, French, German, Greek, Hebrew, Hungarian, Italian, Japanese, Ladino, Lithuanian, Polish, Portuguese, Russian, Slovenian, Somali, Spanish, Thai, Swedish, Vietnamese and Yiddish.

WebAPP is the most fully-featured, versatile, free and open-source, flat-file Perl portal script available today! Acronym for Web Automated Perl Portal ™, WebAPP is easily installed on virtually any UNIX-based server. WebAPP requires no SQL backend, no PHP, only a hosting environment offering support for Perl.
Featuring the most complete (and growing) set of interactive community-building resources available, even an inexperienced webmaster can easily install WebAPP, login and personalize their portal, populate it with their content, and easily maintain, develop and administer the site.

Refer More http://www.web-app.net/