Chris Ridd wrote:
On 11/1/06 8:21, Gergely Sánta <[EMAIL PROTECTED]> wrote:
--Quanah Gibson-Mount wrote:
--On Tuesday, January 10, 2006 5:29 PM +0100 Gergely Sánta
<[EMAIL PROTECTED]> wrote:
Hi!
It seems, the problem is in my perl-experience.. I generated an
another,
bigger bug with my change, the trailing '\n'-s of lines wasn't
removed..
So those lines wasn't equivalent at all :(
I'm attaching a diff of my changes, which now works fine for me..
Generally the standard is to use "diff -u" not just "diff", as the
default output is pretty useless to use to apply as a patch.
--Quanah
Ok, sorry, I didn't know.. Here is the "diff -u" with another little change.
After some googling on $INPUT_RECORD_SEPARATOR ($/), I found that the
difference between '$/ = undef' and '$/ = ""' is, that the second one
will treat two or more consecutive empty lines as a single empty line.
For this reason I added an additional line '$ln =~ s/\n\n+/\n\n/sg;'.
Maybe this isn't the best solution for accepting memory-files too, but
it works fine. I hope, it is not generating another bug to code.. Now
this works for buffers too:
What happens if your string contains lines terminated by "\r\n" (DOS-style)
or just "\r" (Classic MacOS-style) instead of just "\n" (Unix-style)? I'm
not sure if LDIF allows the Classic MacOS-style, but I'm sure it allows the
other two.
I'm too lazy too look ;-) and since you've got the code in your editor...
:-))
Cheers,
Chris
Yep, I had on mind that too, but I also killed too much time for this problem
:( This caused me a 2-day lag in my work, so I have no time for experimenting
with specific cases, sorry. I only know, that this solves my problem (running
on Linux and Solaris), and hope, it will help to others with same needs too.
Added a "\r" removing line, which will allow DOS-style LDIFs. It seems to me,
it not allows MacOS-style, but maybe I'm wrong.
Cheers,
Gergely
--- LDIF.pm 2006-01-11 09:53:03.000000000 +0100
+++ LDIF_rm_modified.pm 2006-01-11 09:52:51.000000000 +0100
@@ -82,7 +82,7 @@
my @ldif;
{
- local $/ = "";
+ local $/;
my $fh = $self->{'fh'};
my $ln;
do { # allow comments separated by blank lines
@@ -93,6 +93,8 @@
$self->eof(1);
return;
}
+ $ln =~ s/\r//sg;
+ $ln =~ s/\n{2,}/\n\n/sg;
$ln =~ s/\n //sg;
$ln =~ s/^#.*\n//mg;
chomp($ln);
@@ -108,6 +110,10 @@
$self->{_next_lines} = $ln;
} until ($self->{_next_lines} || $self->eof());
}
+ # Remove trailing newlines
+ foreach my $ln (@ldif) {
+ chomp $ln;
+ }
@ldif;
}