Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   perl script to replace values in a file (http://www.go4expert.com/forums/perl-script-replace-values-file-t15377/)

rag84dec 3Dec2008 14:09

perl script to replace values in a file
 
Hi all,
I need a perl program to do the following...

I have a File with some values...the file has following values in different lines...

device1
path1
FileName1

I need to write these values in a file in a proper place...
Like in place of "Device" i need to replace it with "device1"
In place of "Path" i need to replace it with "path1"...etc...

Can anyone help me in writing a perl code?

pradeep 18Dec2008 19:30

Re: perl script to replace values in a file
 
Code: Perl

my @data;
open(H,'yourFile.txt') or die $!;
while( my $line = <H>)
{
 push(@data,lc $line);
}

close H;
open(H,'>yourFile.txt') or die $!;
print H join("\n",@data);
close H;



All times are GMT +5.5. The time now is 14:07.