How To write the content in a different file (i.e temp file)and then rename it to th

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • powerfulperl
    New Member
    • Feb 2010
    • 14

    #1

    How To write the content in a different file (i.e temp file)and then rename it to th

    I have the following code, I need to write the content of a file.txt after searching

    for line Local=IN, if found then its o.k if not found then enter the line Local=IN after

    the line 'Testing Option OK'.

    1. open FH, "<file.txt" ;
    2. $/=undef; #set slurp mode
    3. $file_contents= <FH>;
    4. if (index($file_co ntents, "Local=IN") !=-1) { # file doesn't contain string
    5. ($first, $second)=split(/Testion Option OK/, $file_contents) ;
    6. $new_file=$firs t."\nTestion Option OK\nLocal=In\n" .$second;
    7.# write out the new file here
    8. }
    9. close FH;
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Do you understand what that code is doing?

    What did Axweildr say when you asked him to explain the code he gave you?

    Do you know how to open a file and write to it?

    Comment

    Working...