in reply to Extract portion of string based on string separator
The following two also works:
my ($y) = '/a/b/c/d/e/f' =~ m{^(/[^/]+/[^/]+/[^/]+)};
my $y = join('', (split(qr{(?=/)}, '/a/b/c/d/e/f'))[0..2]);
By the way, using $a is a bad habit. Declaring it as a lexical, doubly so.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extract portion of string based on string separator
by Krambambuli (Curate) on Apr 26, 2007 at 08:07 UTC | |
by linuxfan (Beadle) on Apr 26, 2007 at 16:25 UTC |