--- On Tue, 19/1/10, Erez Schatz <moonb...@gmail.com> wrote:
Hi Erez, Thanks for your prompt reply. I have made the changes as per your suggestions. like foreach (@lines) { my $fname = basename($filename ); s/$var/\$Header: $fname 120.0 2007\/11\/27 07:59:52 atgops1 noship \$/; print WRITEFILE $_; } Now, the script is working fine!!!! Regards, Harish From: Erez Schatz <moonb...@gmail.com> Subject: Re: Files are getting blank while using substitute command in script To: "harish behl" <harish_behl1...@yahoo.com> Cc: beginners@perl.org Date: Tuesday, 19 January, 2010, 4:27 PM 2010/1/19 harish behl <harish_behl1...@yahoo.com>: > My Script has to search a particular string like "\$Header\$" in files and if > this string is found, it should replace it with "\$Header > $NameofFile 01/01/2009". But it's making the files blanks. This means you have a problem in the part that is writing to the files, mainly here: > foreach my $line (@lines) You correctly assign each element from @lines to $line, but, the substitution and print are made on the default variable ($_): > s/$var/\$Header: $fname 120.0 2007\/11\/27 07:59:52 atgops1 noship > \$/; > print WRITEFILE $_; Which means the substitution doesn't happen and the file's getting overridden with whatever's in the default variable, in your case, apparently nothing. There are several other issues of correction and practice in your program, and I do encourage you to uncomment 'use strict' in your second line, but I believe that's the immediate solution to your issue. -- Erez "The government forgets that George Orwell's 1984 was a warning, and not a blueprint" http://www.nonviolent-conflict.org/ -- http://www.whyweprotest.org/ Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php