hello monks
I'm working on a subroutine, which is supplied with a url, which will always include at least one get variable, like http://google.com/?search=ahoy, which isn't a problem. However when there are multiple get variables in the url, I need to store all of them, without their values, just the variable names. So far I've got:
sub check {
my $url = "http://google.com/?var1=aaaa&var2=aa";
my $count = 0;
my @arr;
return undef if $url !~ /^http:\/\/.*?\?.*?=.*?$/i;
$count++ while $url =~ /&/g;
$url =~ s/^(.*?=)(.*?)$/$1/ and return $url if $count<1;
$arr[0..$count] = $url =~ /^http:\/\/.*?\?(?:([\w\d]*=)(?:.*[&]?))*/gi
+;
say $_ foreach @arr;
}
I need to store "var1=" and "var2=" into the array, however extending it to any other possible variables (if there was var3, var4 etc.)
And I am having major problem with the last regex, I've tried many variations, and this one as well throws a warning. So basically any ideas, how to achieve the task described above would be greatly appreaciated. Also regular expressions aren't exactly familiar to me that much so I'm aiming to improve my regex as much as possible, so I'd greatful for any criticims on the other regex included...
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.