Gossamer Forum
Home : General : Perl Programming :

Subset of a variable

Quote Reply
Subset of a variable
If $quote = "The big brown fox jumped over the old wooden fence."

then is there a way in perl that I can say I want $quote1 to equal all that which is between brown and wooden so that $quote1 = "brown fox jumped over the old wooden"

Thanks in advance.
Quote Reply
Re: Subset of a variable In reply to
Hi,

Give:

$begin = quotemeta ("brown");
$end = quotemeta ("wooden");
$string = "The big brown fox jumped over the old wooden fence";

if (/($begin.+?$end)/omi) {
$match = $1;
}
else {
# no match
}

a shot. If you don't want to include the begin and end markers, just use:

if (/$begin(.+?)$end/) {

Hope that helps,

Alex