Peterpion has asked for the wisdom of the Perl Monks concerning the following question:
etc. I've got a lot of these in a bit of code I have been working on and its taking a lot of space, so I would prefer to do something likemy $string = 'abcdef'; my $extracted = ''; if ($string =~ m/bce/) { $extracted = $1; } my $extracted2 = ''; if ($string =~ m/ced/) { $extracted2 = $1; }
but that dosent work. Just thinking this must have been done a million times already and what the most tidy way others do it is.my ($extracted) = ($string =~ m/bce/)||('');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tidiest extract or define method?
by BrowserUk (Patriarch) on Mar 28, 2014 at 11:25 UTC | |
|
Re: Tidiest extract or define method?
by Don Coyote (Hermit) on Mar 28, 2014 at 11:26 UTC | |
|
Re: Tidiest extract or define method?
by AnomalousMonk (Archbishop) on Mar 28, 2014 at 19:16 UTC |