in reply to Re: Re: backward split
in thread backward split
#!/usr/bin/perl -w use strict; my $string = "foo.bar.foobar"; my ($val1,$val2) = split /\.(?!.*\.)/,$string; print "$val1,$val2\n";
update:and another way:
update:Apparently, I suffer from not enough laziness, as in the end would probably have kept thinking there has to be a more elegant solution, and would hopefully stumbled upon sauoq's solution below at some point, which I think is the best solution, but leave the above code if only to show TMTOWTDI.#!/usr/bin/perl -w use strict; my $string = "foo.bar.foobar"; my $position = rindex($string,'.'); my ($val1,$val2) = ( substr($string,0,$position++), substr($string,$position) ); print "$val1,$val2\n";
-enlil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: backward split
by sauoq (Abbot) on Jun 01, 2003 at 01:37 UTC |