replace string contaning /n
am 13.11.2007 10:46:36 von cieux87-finhello.
I try to change the string \nE by # E without success.
$line=~ s/(\n\E/#E/g;
Thank you in advance for your assistance.
hello.
I try to change the string \nE by # E without success.
$line=~ s/(\n\E/#E/g;
Thank you in advance for your assistance.
On Nov 13, 10:46 am, cieux87-...@yahoo.com wrote:
> hello.
>
> I try to change the string \nE by # E without success.
>
> $line=~ s/(\n\E/#E/g;
>
> Thank you in advance for your assistance.
Is it the string constant '\nE' that you'd like to replace or do you
want to replace all line breaks by '#' which are being followed by
'E'?
And what does the '(' in your regex stand for?
In the first case
$line=~ s/\\nE/#E/g;
in the 2nd case
$line=~ s/\nE/#E/g;
Cheers,
Steffen
cieux87-fin@yahoo.com
> I try to change the string \nE by # E without success.
>
> $line=~ s/(\n\E/#E/g;
That does not even compile.
Two pieces of information are needed to evaluate the behavior
of a pattern match, the pattern and the string that it is
trying to match against.
We need to see the contents of $line.
Your choice of variable name implies that the answer is
given in the Perl FAQ:
perldoc -q match
I'm having trouble matching over more than one line. What's wrong?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
On 13 nov, 11:13, sheinr...@my-deja.com wrote:
> On Nov 13, 10:46 am, cieux87-...@yahoo.com wrote:
>
> > hello.
>
> > I try to change the string \nE by # E without success.
>
> > $line=~ s/(\n\E/#E/g;
>
> > Thank you in advance for your assistance.
>
> Is it the string constant '\nE' that you'd like to replace or do you
> want to replace all line breaks by '#' which are being followed by
> 'E'?
> And what does the '(' in your regex stand for?
>
> In the first case
> $line=~ s/\\nE/#E/g;
>
> in the 2nd case
> $line=~ s/\nE/#E/g;
>
> Cheers,
> Steffen
Hello
Here a solution.
# replace all \n by space
sub chg_file {
# Open file to modify for reading
open(INPUTF,$ARGV[0]);
while(
if (m/^E /) {
print OUTFILE "\n" unless $lin < 2;
}
print OUTFILE " " unless m/^E /;
chop $_;
print OUTFILE $_;
$lin++;
}
print OUTFILE "\n";
close(OUTFILE);
close(INPUTF);
}
On 13 nov, 12:59, Tad McClellan
> cieux87-...@yahoo.com
> > I try to change the string \nE by # E without success.
>
> > $line=~ s/(\n\E/#E/g;
>
> That does not even compile.
>
> Two pieces of information are needed to evaluate the behavior
> of a pattern match, the pattern and the string that it is
> trying to match against.
>
> We need to see the contents of $line.
>
> Your choice of variable name implies that the answer is
> given in the Perl FAQ:
>
> perldoc -q match
>
> I'm having trouble matching over more than one line. What's wrong?
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
hello
Here a solution.
# replace all \n by space
sub chg_file {
# Open file to modify for reading
open(INPUTF,$ARGV[0]);
while(
if (m/^E /) {
print OUTFILE "\n" unless $lin < 2;
}
print OUTFILE " " unless m/^E /;
chop $_;
print OUTFILE $_;
$lin++;
}
print OUTFILE "\n";
close(OUTFILE);
close(INPUTF);
}
cieux87-fin@yahoo.com
> On 13 nov, 12:59, Tad McClellan
>> cieux87-...@yahoo.com
>> > I try to change the string \nE by # E without success.
>>
>> > $line=~ s/(\n\E/#E/g;
>>
>> That does not even compile.
>>
>> Two pieces of information are needed to evaluate the behavior
>> of a pattern match, the pattern and the string that it is
>> trying to match against.
>>
>> We need to see the contents of $line.
>>
>> Your choice of variable name implies that the answer is
>> given in the Perl FAQ:
>>
>> perldoc -q match
>>
>> I'm having trouble matching over more than one line. What's wrong?
>>
>> --
>> Tad McClellan
>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>
> hello
>
> Here a solution.
I did not ask a question...
> sub chg_file {
> # Open file to modify for reading
> open(INPUTF,$ARGV[0]);
You should always, yes *always*, check the return value from open():
open(INPUTF, $ARGV[0]) or die "could not open '$ARGV[0]' $!";
> if (m/^E /) {
> print OUTFILE "\n" unless $lin < 2;
> }
> print OUTFILE " " unless m/^E /;
if (m/^E /) {
print OUTFILE "\n" unless $. < 2;
}
else {
print OUTFILE " ";
}
> chop $_;
That is how you removed newlines 10 years ago. Where did you
learn your Perl?
chomp $_;
> $lin++;
You don't need to maintain a line counter yourself, perl is already
doing that for you, just use it ($.).
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"