in reply to Pattern match for split() - need match but not match syntax

You are almost there, include the condition inside the split pattern:

use strict; my $app_text = "one:partridge\ntwo:\nturtle doves\nthree:french hens\n +"; foreach my $line (split /(?<!:)\n/, $app_text) { $line =~ s/\n//g; # Eliminate internal "\n"s print "$line\n"; }

Outputs

one:partridge two:turtle doves three:french hens

Update: Corrected the split pattern to use lookbehinds, see perlre

citromatik

Replies are listed 'Best First'.
Re^2: Pattern match for split() - need match but not match syntax
by Tanoti (Initiate) on May 06, 2008 at 14:52 UTC
    Thanks, that works a treat and has saved a lot of case-specific workaround code. I had played with the lookbehind syntax but couldn't get them to work so thought I was on the wrong track!

    John