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.
   Here I have use Split operator to get the extension of filename.


#! /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;
print $filetoopen;
open(IN, "<$filetoopen") || die "cannot open file\n";
open(OUT, ">$test") || die "cannot open file\n";
while (<IN>){
if (/$com/){
        s/$com/td>\n<\\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","$filetoopen");
}}

 Thanks inadvance,
 Prabu.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.620 / Virus Database: 399 - Release Date: 3/11/2004




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to