Mailing List Archive

Re: Fast lexical typing and fun with REXP's
Still interested if there is another way... my

rexp is getting rather longish...

But, I have run across an interesting problem that I've not run into before
(having not needed quite as complex an overall expression as this)

If you have
(xxxx (yyyyy))

how do you get the inner value? ie

(xxxxx yyyyy)

would go into $1. Is there anyway to do this if you have to group both, but
actually only want part of the grouped item?
Re: Fast lexical typing and fun with REXP's [ In reply to ]
I was going to send this answer just to the person who asked the question,
but the return address seems to have been corrupted (unless you're willing
to believe in a machine or domain named "@").

> Date: Thu, 14 Sep 95 19:27:05 BST
> From: Dale Amon <amon@@>
> To: perl5-porters@africa.nicoh.com
> Subject: Re: Fast lexical typing and fun with REXP's
>
> Still interested if there is another way... my
>
> rexp is getting rather longish...
>
> But, I have run across an interesting problem that I've not run into before
> (having not needed quite as complex an overall expression as this)
>
> If you have
> (xxxx (yyyyy))
>
> how do you get the inner value? ie
>
> (xxxxx yyyyy)
>
> would go into $1. Is there anyway to do this if you have to group both, but

I think of this as $<N> recovering the expression corresponding to the N'th
left parenthesis. Here's a simple f'rinstance:

----------
$_ = "first_part second_part";

m/(first_part (second_part))/;
print "\$1 is '$1', \$2 is '$2'\n";

m/((first_part) (second_part))/;
print "\$1 is '$1', \$2 is '$2', \$3 is '$3'\n";
----------

This prints:
----------
$1 is 'first_part second_part', $2 is 'second_part'
$1 is 'first_part second_part', $2 is 'first_part', $3 is 'second_part'
----------


pete peterson
rep@genrad.com
(508)287-7478; Home: (508)256-5829 (Chelmsford, MA)