From: Rory Winston (Rory.Winston at domain telewest.co.uk)
Date: Tue 16 Oct 2001 - 15:41:13 IST
Hi,
Is it possible to use Perl to match any number of parentheses using a regex?
For example, if I have an entry like the following:
A = ( abc ( b = def ( c = efg ) ) )
B = (abc)
C = (
(a = abc)
(f = ghi)
)
..etc. (basically each entry can be split over multiple lines, and have an
arbitrary number of parameters enclosed within parentheses). I would like to
be able to match the beginning of each entry, e.g. parsing the above file
results in
A
B
C
But I'm not sure how to manage the arbitrary number of ( and ) for each
entry. If I was doing this in C, I could use a pushdown stack to to track
the number of parentheses. Is there an elegant way to do this in Perl? (I've
found more elegant ways to do things in Perl than I ever thought possible
with a single language, but this one has eluded me so far.. :-))
Cheers!
Rory
--------------------------------------------
Rory Winston,
Developer,
OneLine Team,
TeleWest Communications,
Genesis Business Park,
Albert Drive,
Woking Surrey,
GU21 5RW
mailto: rory.winston at domain telewest.co.uk
phone: 01483 295 653
------------------------------------------------------------------------------
Live Life in Broadband
www.telewest.co.uk
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material.
Statements and opinions expressed in this e-mail may not represent those of the company. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender immediately and delete the material from any computer.
==============================================================================
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:12:46 GMT