First you can drop the Windows centric paths and use / instead of \ Perl will supply Windows with the correct path delimiters for the platform automagically changing / into \ as required.

The path is not however your problem. As you open the file for read/write you need to remember that at the end of the read you are at EOF so you need to seek the begining of the file and also truncate it to 0 unless you want to run the risk of getting crap at the end. I have added as die to the print CONFIG (remove the seek and truncate and you will get the error). This runs fine now. BTW don't open STDERR ">error.log" without including some path info. Even ./ for the current working directory makes it obvious where to look for this file. Also when you read data in from a file the newlines will still be there so you don't need to add more in your substitution

open(CONFIG, "+<c:/blah.txt" ) or die "Can't open blah.txt: $!"; my @configfile = <CONFIG>; seek CONFIG, 0, 0; # go to start of file for overwrite truncate CONFIG, 0; # get rid of old file foreach my $configfile (@configfile) { $configfile =~ s/serverport 111$/serverport $port/; print CONFIG $configfile or die $!; } close(CONFIG); close(STDERR);

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: modifying a text file on Win32 by tachyon
in thread modifying a text file on Win32 by Anonymous Monk

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.