in reply to A split ing headache
my $string = 'see:how:they:code'; my($zeroth, $first, $remainder) = split ':', $string, 3; print $zeroth, "\n", # see $first, "\n", # how $remainder, "\n"; # they:code
If you want to actually truncate the leftover list elements, try this:</o>
my($zeroth, $first, $second) = (split ':', $string)[0..2]; print $zeroth, "\n", # see $first, "\n", # how $second, "\n"; # they
And 'code' just goes away. Just watch your parens, because this is wrong:
split(':', $string)[0..2]Hopefully you can see why.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (take two...) Re: A split ing headache
by extremely (Priest) on Dec 12, 2000 at 14:19 UTC | |
by japhy (Canon) on Dec 12, 2000 at 19:37 UTC | |
by extremely (Priest) on Dec 13, 2000 at 09:05 UTC |