[NEWBIE] newline question
From: Jan Biel (jan.biel_at_tu-clausthal.de)
Date: 03/31/04
- Next message: John Bokma: "Re: count files + dirs"
- Previous message: Richard S Beckett: "Re: Array from a string."
- Next in thread: Richard Morse: "Re: [NEWBIE] newline question"
- Reply: Richard Morse: "Re: [NEWBIE] newline question"
- Reply: Gunnar Hjalmarsson: "Re: [NEWBIE] newline question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 19:25:38 +0200
Hello!
>From some tutorials on the web I managed to create a perl script which finds
and replaces certain occurences in text files via regular expressions.
Then something happened which I cannot really explain, so I hope you can
clarify it for me.
The original perl script looks like this:
-------------------------------
$filein = 'a.txt';
$fileout = 'b.txt';
open(INFO, $filein);
open(INFO2, ">$fileout");
@lines = <INFO>;
grep(s/\n//g,@lines);
grep(s/ab/found/g,@lines);
print INFO2 @lines;
close(INFO);
close(INFO2);
--------------------------------
where a.txt is a file containing:
--------------------------------
a
b
c
--------------------------------
The resulting b.txt contains:
--------------------------------
abc
--------------------------------
So the second regular expression is ignored.
But if I write two perl scripts where each executes only one of the regular
expressions it works with the result:
--------------------------------
foundc
--------------------------------
as expected.
What is the mystery here?
I hope this wasn't too confusing :)
Janbiel
- Next message: John Bokma: "Re: count files + dirs"
- Previous message: Richard S Beckett: "Re: Array from a string."
- Next in thread: Richard Morse: "Re: [NEWBIE] newline question"
- Reply: Richard Morse: "Re: [NEWBIE] newline question"
- Reply: Gunnar Hjalmarsson: "Re: [NEWBIE] newline question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|