in reply to Matching enclosed expression

If you know the name of the param ahead of time, you can let URI::QueryParam do the work instead:
use URI; use URI::QueryParam; my $u = URI->new('http://www.com/index.pl?id=<idparm>&etc'); print $u->query_param('id'), "\n";
UPDATE:
Actually, you don't even have to know the name of the param ahead of time - UPDATE, oops - i didn't quite do this right the first time, here goes again:
my $u = URI->new('http://www.com/index.pl?id=<idparm>&foo=bar&etc'); my @val = grep /<([^>]+)/, map $u->query_param($_), $u->query_param(); print $_,$/ for @val;
But BrowserUk has a point ... this is waaay overkill! At this point we might as well have just used:
@value = $URL =~ /(<[^>]+>)/;
But what if it's the key that you want and not the value? What if both keys and values are surrounded with brackets and you only want the keys? Sometimes importing 400 lines of code is better than spending 400 minutes trying to get you own solution correct.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: Matching enclosed expression (downvote opportunity!)
by BrowserUk (Patriarch) on Sep 15, 2003 at 02:48 UTC

    300 lines of URI

    PLUS 100 of URI::QueryParam

    PLUS grep

    PLUS a regex,

    when the regex alone (slightly modified) does the job? I don't get the logic?

    If you need to parse a URI--ie extract the protocol, hostname, path, etc. etc,--then use these well-written, RFC-complient solutions--but if you need to extract one, small, easily defined, nicely delimited piece of text from another piece of text, then do what the Practical Extraction & Reporting Language is good at, use the highly optimised, much-copied & envied, incredibly powerful, highly-prized regex engine to extract that one piece of text from the other.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.