This is an unusual problem that I encountered (and probably saw it before, but did not pay attention to it).
Here's the gist of the code:
my $url = 'http://twitter.com/' . $handle; my $page = get($url); if($page =~ m/Web<\/span>\s*<a href=\"(.+?)\"/gi) { $website = $1; } if($page =~ m/follower_count\" class=\"stats_count numeric\">(.+?)\s*</g) { $num_followers = $1; }
It gets the twitter url and performs some regular expression to capture # followers and the user's website. This code is working fine. But when you switch the order and look for the site AFTER you are looking for a follower, the website becomes empty. As it turned out, with regular expression, the string seems to save the location where the last match was made. In html, the number of tracking elements appears after the website is displayed. If you first do regular expression of the follower counter, he, like him, will run the regular expression of the website where the follower counter is left (for example, an index link to a string).
What puzzled me was that I had the “g” operator at the end, meaning “global,” as in “searching for a line globally ... from the very beginning”.
Am I missing something? I cannot understand why it resumes the last position of the regular expression in the string (if that makes sense).
source share