Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I need to know wether it is possible to match a patter such as the following:
SELECT ..... where a.owner = b.owner && c.index_owner=d.owner.... //mo +re like this
Here, I need to match wether .owner or .index_owner or .table_owner or .sequence_owner is present on the lhs, and if present, need to store all the aliases (the part before the . , ir a and c in this case.._ in an array..? )

Please guide on how to do it w/o using an interative loop...

Regards

Abhinav

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: Multple Matches using Regexp?
by tachyon (Chancellor) on Sep 15, 2003 at 12:17 UTC

    You will probably need to post a clearer explanation. It sounds like you are after the @ary = $str =~ m/(stuff)/g idiom like in the do block. This looks for all (/g) the matches (m//) on 'stuff' (m/stuff/) in $str, captures them in $1 sequentially (m/(stuff)/) and saves them into @ary. Something like this will probably do what you want.

    Update

    There was not an 'Idioms Explained' on this common one so I wrote it Perl Idioms Explained - @ary = $str =~ m/(stuff)/g

    $str = 'SELECT ..... where a.owner = b.owner && c.index_owner=d.owner. +...'; $str =~ m/\.(owner|index_owner)\s*=/ && do{ @alias = $str =~ m/(\w+)\. +\w/g }; print "@alias";

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print