Thursday, June 29, 2006

reading a dir

use Cwd;
my @files;
opendir (DIR, $dirname) or die $!;
my @dir = readdir DIR;


foreach my $item1 (@dir){
    if ($item1 ne “..” || $item1 ne “.”){
        push @files ,$item1;
    }
}
closedir DIR;

Posted by Babai at 14:23:34 | Permalink | No Comments »

Wednesday, June 21, 2006

One line Email validation using JavaScript regex

Validate if the string passed in a valid email or not

returns true or false 

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

returnval=emailfilter.test(<Email address to be tested >);

 

 

Posted by Babai at 09:30:51 | Permalink | No Comments »

Inserting a new line character on every nth occurrence of a space

in the below code  the 2 can be replaced  with n number and \s is for space and \n for new line charecter 

$string  =~ s/(\s)/(++$count%2==0)?”\n”:$1/ige;

Posted by Babai at 06:34:56 | Permalink | No Comments »

Monday, June 5, 2006

Read pdf file and send it to browser

#!/usr/local/bin/perl

my $file_name = “/apps/intranet/ns-home/Apache_Server/Public/TechCouncil/TIITC/2006/data/a0756159_1148893709_Karnataka%20Map.pdf”;

open(FILE, “< $file_name”) or die (“$!”);

while (<FILE>) {

            $File .= $_;

}

close FILE;

print “Content-Type: application/pdf”, “\n”;

print “Content-Disposition: Attachment; filename=Abc.pdf”, “\n\n”;

print $File;

Posted by Babai at 14:27:26 | Permalink | No Comments »