Update: i Could break down the lengthy question to a simple:
How to overwrite a given line in a file with another line without appending?.
#!/usr/bin/perl use strict; use File::Copy; use warnings; my $open_file= "C:/oracle/ora81/network/ADMIN/SQLNET.ORA"; my $write_file=">>C:/oracle/ora81/network/ADMIN/SQLNET.ORA"; open(IN,$open_file) || die "cannot open $open_file $!"; open(OUT,$write_file) || die "cannot create $write_file $!"; while (<IN>) { if ($_ = /^SQLNET\.AUTHENTICATION_SERVICES=\ \(NTS\)$/){ print "\#\ ^SQLNET\.AUTHENTICATION_SERVICES=\ (NTS)"; print OUT $_ "\#\ SQLNET\.AUTHENTICATION_SERVICES=\ (NTS)"; #Want to write the 2nd string print ... to OUT write handle #OUT $_ } }
I want the print state in the while loop to write to the OUT Filehandle, i got a syntax error if i try this? Any Ideas where my error is? error message:
String found where operator expected at ora.pl line 22, near "$_ "\#\ + SQLNET\.AUTHENTICATION_SERVICES=\ (NTS)"" (Missing operator before "\#\ SQLNET\.AUTHENTICATION_SERVICES=\ (N +TS)"?) syntax error at ora.pl line 22, near "$_ "\#\ SQLNET\.AUTHENTICATION_ +SERVICES=\ (NTS)"" Execution of ora.pl aborted due to compilation errors.


Thanks
MH


In reply to Search and Replace line by line not working on Filehandle by matze77

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.