1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

perl script to replace values in a file

Discussion in 'Perl' started by rag84dec, Dec 3, 2008.

  1. rag84dec

    rag84dec New Member

    Joined:
    Jul 17, 2007
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Code:
    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;
    
     

Share This Page