Sunday, September 19, 2010

Why should I use the -w argument with my Perl programs?

Many Perl developers use the -w option of the interpreter, especially during the development stages of an application.

This warning option turns on many warning messages that can help you understand and debug your applications.

To use this option on Unix systems, just include it on the first line of the program, like this:
#!/usr/bin/perl -w

If you develop Perl apps on a DOS/Windows computer, and you're creating a program named myApp.pl, you can turn on the warning messages when you run your program like this:

perl -w myApp.pl

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/

Thursday, March 4, 2010

difference between soft link and hard link

Hard Links :

1. All Links have same inode number.

2.ls -l command shows all the links with the link column(Second) shows No. of links.

3. Links have actual file contents

4.Removing any link just reduces the link count but doesn't affect other links.

Soft Links(Symbolic Links) :

1.Links have different inode numbers.

2. ls -l command shows all links with second column value 1 and the link points to original file.

3. Link has the path for original file and not the contents.

4.Removing soft link doesn't affect anything but removing original file the link becomes dangling link which points to nonexistant file.

Tuesday, February 9, 2010

Changing your default UNIX file permissions

To change the default permissions assigned to your UNIX files and directories, use the umask command. umask is a little confusing at first. Its format is

umask nnn

where nnn is a three-digit code that defines the new default permissions. The umask string does not have the same format as the the chmod permission string.

Each of the three numbers represents one of the categories user, group, and other. The value for a category is calculated as follows:

read permission has a value of 4
write permission has a value of 2
execute permission has a value of 1

Sum the permissions you want to set
for the category, then subtract that
value from 7.

As an example, examine the current default umask statement that is used to assign the file protections -rwx-r-x--- :

umask 027

The user category value is 0 because r+w+x = 4+2+1 = 7. When this is subtracted from 7, the value is 0.

The group category value is 2 because r+x = 4+1 = 5. When this is subtracted from 7, the value is 2.

The other category value is 7 because no permissions = 0. When this is subtracted from 7, the value is 7.