Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
but, after checking the manpage on split realized it would not work. So I tried this:my @splits = split(/\./,$string,-2);
The above code works, but it seems there should be a better way. Ideas?#!/usr/bin/perl -w use strict; my $string = "foo.bar.foobar"; my($val2, $val1) = split(/\./,(reverse $string),2); $val1 = reverse($val1); $val2 = reverse($val2); print "$val1, $val2\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: backward split
by sauoq (Abbot) on Jun 01, 2003 at 01:15 UTC | |
by jeffa (Bishop) on Jun 01, 2003 at 01:58 UTC | |
|
Re: backward split
by BrowserUk (Patriarch) on Jun 01, 2003 at 01:18 UTC | |
by Aristotle (Chancellor) on Jun 01, 2003 at 12:04 UTC | |
|
Re: backward split
by Enlil (Parson) on Jun 01, 2003 at 00:35 UTC | |
by Anonymous Monk on Jun 01, 2003 at 00:51 UTC | |
by Enlil (Parson) on Jun 01, 2003 at 01:00 UTC | |
by sauoq (Abbot) on Jun 01, 2003 at 01:37 UTC | |
|
Re: backward split
by Limbic~Region (Chancellor) on Jun 01, 2003 at 01:00 UTC | |
|
Re: backward split
by athomason (Curate) on Jun 01, 2003 at 01:04 UTC | |
|
Re: backward split
by arthas (Hermit) on Jun 01, 2003 at 13:12 UTC | |
by Aristotle (Chancellor) on Jun 01, 2003 at 13:47 UTC | |
|
Re: backward split
by edoc (Chaplain) on Jun 01, 2003 at 02:50 UTC |