Dear Monks,
I have a textfile looking like this:
Dit is een voorbeeldtekst
The quick brown fox jumps over the lazy dog.
SOURCEREPOSITORYNAME
Roses are red, violets are blue
And Osama Is coming To Kill you
I want to change it in this:
Dit is een voorbeeldtekst
The quick brown fox jumps over the lazy dog.
SOURCEREPOSITORYNAME=Development
Roses are red, violets are blue
And Osama Is coming To Kill you
To achieve this epic feat, I wrote the following piece of code (roughly based on my camel):
#!perl -w
use strict;
my $line;
my $CTLfile = 'y:\perl\test.ctl';
local $^I = '.bak';
open (CTLHANDLE, "+<$CTLfile");
while($line=<CTLHANDLE>){
$line =~ s/SOURCEREPOSITORYNAME/SOURCEREPOSITORYNAME=Development/g
+;
print CTLHANDLE "$line";
}
close(CTLHANDLE);
undef $^I;
This renders the following output:
Dit is een voorbeeldtekst
The quick brown fox jumps over the lazy dog.
SOURCEREPOSITORYNAME
Roses are red, violets are blue
And Osama Is coming To Kill youDit is een voorbeeldtekst
Dit is een voorbeeldtekst
ver the lazy dog.
ver the lazy dog.
E
E
es are red, violets are blue
es are red, violets are blue
uu
I cannot explain this. I know there are modules helping for in place editing, but I don't want to use them. can someone explain the output, why it looks like this and what I can do to achieve my goal?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.