in reply to Easy Split
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.#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Easy Split
by massa (Hermit) on Jul 06, 2009 at 17:25 UTC | |
by Marshall (Canon) on Jul 06, 2009 at 17:44 UTC |