Hi,
> I am unable to modify the input file ,

> If I am redirecting output to with different file name it working fine
> In want to replace name in a file

> $filename = <STDIN>;
> open(OUTPUT,">filename");

As I understand, you want to modify $filename. so second line is
actually :
open(OUTPUT,">$filename");
             ^^^
So, when you open the same file with > you erase its content and erase
the content of INPUT filehanfle as well.

To protect the content of the input file, you can assign an array.

open (IN, $filename);
@content = <IN>;

# then,
open (OUT, ">$filename");

But it would be best, first you create a temporary file, finally copy
its content into $filename. By some reason your script may fail in an
unpredicted line, and your file is gone...




print " Enter the file Name \n";
$filename = <STDIN>;

# probably you want no newline char at the end of a filename.
# chomp erases newline, return carriage character from the end of a
# string 
chomp($filename);

open(INPUT,"<$filename");

#save content of file and filehandle 
@INPUT = <INPUT>;

open(OUTPUT,">filename");

foreach (@INPUT)
{
        if($_ =~ s/FRCC/FRE/)
        {
                print OUTPUT "$_";
        }
        else
        {
                print OUTPUT "$_";

        }
}



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


Reply via email to