[LA.pm] split() question
Benjamin J. Tilly
ben_tilly at operamail.com
Thu Sep 28 16:33:08 PDT 2006
"William Yardley" <lapm at veggiechinese.net> wrote:
>
> I'm doing some maintenance on a CPAN module I didn't write
> (Mail::DeliveryStatus::BounceParser), and (around line 356 if anyone
> needs to actually look there), we do something like:
>
> foreach my $para (split /\n{2,}/, $delivery_status_body) {
> my $report = Mail::Header->new([split /\n/, $para]);
>
> What's strange, is that in some cases, there is a leading \n left, which
> results in $report not having the stuff we expect there. I'd assume that
> since the \n{2,} should be greedy, there wouldn't be any \ns left after
> that split. However, if I print out $para inside the loop, I see a
> leading \n.
Is it possible that your data looks like "\nstuff\n\n\nmore stuff"? Then the first string has a \n at the start that the split is not going to catch.
But if the \n is starting on the second string, then that is a bug. I would create a minimal test example and report it. Then workaround the bug in any way you can.
> Simply doing a:
> $para =~ s/\A\n+//g;
> in between those two lines "fixes" the problem - but I was wondering if
> anyone know why this is happening.
You have my top two guesses in order. First, $delivery_status_body sometimes starts with \n, and failing that that there is Perl bug. The third most likely possibility is that you have a Heisenbug, which you'd notice by your inability to produce a minimal test case. I have no useful suggestions for what to do then.
Cheers,
Ben
More information about the Losangeles-pm
mailing list