Hi,
    I have wrote a script to search for a pattern and replace it in all files of a 
directory,that i specified at commandline.I want another one thing is to be done in 
the script.That's,it should search only for the type of files I specified at 
commandline.That is,it should get the extension of file name and search only those 
files in the directory.
 
   I have made a attempt in this script,but it goes on asking extension for all the 
files in directory.
   Plz help me in getting the things right in the following script.
   Tell the changes to be made in this.
 
#! /usr/bin/perl 

print "Enter a path name: ";
my $path=<STDIN>;
chomp($path);
opendir THISDIR, "$path" or die "serious dainbramage: $!";
my @allfiles = readdir THISDIR;
 
# get all files
foreach $file (@allfiles){
$filetoopen = $path ."/" .$file;
 
# filter to check the type of file
print "Enter the type of extension:";
my $ext=<STDIN>;
chomp($ext);
($str1,$str2) = split(/./, $filetoopen);
if($str2 eq $ext)
{
print $str2;
$filetoopen1 = join(".",$str1,$str2);
print $filetoopen1;
open(IN, "<$filetoopen1") || die "cannot open file\n";
open(OUT, ">$test") || die "cannot open file\n";
while (<IN>){
if (/$com/){
        s/$com/td>\n</g">\\script>/g;
}
if (/$img/){
        s/$img/\n<script>\n<img/g;
}
if (/$pattern/){
        s/$pattern/$own/g;
#   print $_;
}
if (/img/){
        s/$img/document.write("<img/g;
}
if (/$com/){
        s/$com/td>");/g;
}
print OUT $_;
}
close (OUT);
close (IN);
rename("$test","$filetoopen1");
}
}
__END__

 
 Thanks inadvance,
 Prabu.


Win an evening with the Indian cricket captain: Yahoo! India Promos.

Reply via email to