@urls= $field =~ /<a.*?href="(.*?)".*?>.*?<\/a>/mgo; #multi-line, global, compile-once
@text= $field =~ /<a.*?href=".*?".*?>(.*?)<\/a>/mgo;
for ($count=0; $count<(scalar @urls); $count++){
print "\"".$text[$count]."\" goes to ->\"".$url[$count]."\"\n";}
What is the correct syntax to make this the same as the previous lines?
(@array_of_links->{"url"}, @array_of_links->{"text"}) = $field =~ /<a.*?href="(.*?)".*?>(.*?)<\/a>/mgo;
for ($count=0; $count<(scalar @array_of_links); $count++){
print "\"".$array_of_links[$count]{"text"}."\" goes to ->\"".$array_of_links[$count]{"text"}."\"\n";}
I think you want is:
The
/oregex modifier does nothing if no strings are interpolated into it (and it probably shouldn’t even be used then because of its surprising behavior). The/mregex modifier does nothing because you don’t have the^or$anchors in your regex.You can’t create an array of hashes that way. You may want to reread
perldoc perldsc.C-Style
forloops are generally not required in Perl 5. The iteratingforloop is much better. If you need to know the index into an array, you should use the range operator:Perl 5 allows you to choose your own delimiters for strings and regexes if you use their general forms (e.g.
m//for regexes andqq//for double quotes). You can use this to avoid having to use ugly escapes that make your strings and regexes hard to read.However, it looks like you are trying to use a regex to parse HTML. This is a path that is filled with pain. You should really be looking into how to use a parser instead.