in reply to Easy Split

Wow! I guess this wasn't that "easy". It is tricky.
#!/usr/bin/perl -w use strict; my $string = '111111111:22222\:2222:333333333:4444444'; $string =~ s/\\:/:/; #translate \: to just : #the "trick" and its all over now... chomp ($string); #don't worry about trailing \n my @strings = split (/:/,$string); foreach my $line (@strings) { print "$line\n"; } __END__ prints: 111111111 22222 2222 333333333 4444444
Update: the above code produces exactly what the OP asked for, but it could be that 22222\:2222 is a typo and that this "2" string doesn't include a backslash. If so then just split on [:\n] or something like that.

Replies are listed 'Best First'.
Re^2: Easy Split
by massa (Hermit) on Jul 06, 2009 at 17:25 UTC
    Trickier than it seems :-D Apparently, the OP wants NOT to split on '\:'; so the answer should be:
    111111111 22222\:2222 333333333 4444444
    []s, HTH, Massa (κς,πμ,πλ)
      I think that we have all done a great job of presenting various alternatives. Hooray! I think it is now up to the OP to say what he thinks about our suggestions. I tried. You tried. A bunch of folks have tried. It is pointless for us to argue about what the OP wanted. Let's see what develops. One of the possible scenarios is that the OP says thanks to everybody. We have all tried to help.