[NEWBIE] newline question

From: Jan Biel (jan.biel_at_tu-clausthal.de)
Date: 03/31/04


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



Relevant Pages

  • Re: Replacing a text in multiple files with regular expressions
    ... > to replace all occurrences of: ... The problem is that wildcards does not work with my ... Luckily I found a perl script that does exactly what I need. ...
    (comp.lang.perl.misc)
  • Re: Find repeating substring
    ... My mistake. ... I ran the Perl script with your suggestion and no ... Regular expressions are pretty much like ...
    (comp.lang.perl.misc)
  • RE: Newbee question on regular expressions
    ... Can you clarify the following questions? ... What is the significance of the open and close paranthesis? ... > Jorge Serrano ... >> I am trying to learn about regular expressions. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: if with or
    ... The brackets are not required, but I find they clarify what is being ... Or possibly look at Regular Expressions if the patterns are more ...
    (microsoft.public.excel.programming)
  • Re: Format string using regular expressions
    ... Regular expressions are used to parse strings, not to format them. ... you clarify why you think you need them here? ...
    (microsoft.public.dotnet.framework)