Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3630794
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:18:54+00:00 2026-05-19T00:18:54+00:00

This is an oddball issue I’ve encountered (and probably have seen before but never

  • 0

This is an oddball issue I’ve encountered (and probably have seen before but never paid attention to).

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 a twitter url and does a bit of regex to capture the # of followers and the website of the user. This code actually works fine. But when you switch the order and search for the website AFTER you search for follower, website comes up empty. As it turns out, when you regex a string, it seems to sort of save the location of where that last match was made. In the html, the follower count comes up after the website display. If you do the follower count regex first, it’s like it starts up the website regex where the follower count left off (like an index reference to the string).

What has me baffled is that i have the “g” operator at the end, signifying “global”, as in “search the string globally… from the beginning”.

Am I missing something here? I can’t seem to figure out why it’s resuming the last regex position on the string (if that makes sense).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:18:55+00:00Added an answer on May 19, 2026 at 12:18 am

    The /g modifier, in scalar context, doesn’t do what you think it does. Get rid of it.

    As perlretut explains, /g in scalar context cycles over each match in turn. It’s designed for use in a loop, like so:

    while ($str =~ /pattern/g) {
        # match on each occurence of 'pattern' in $str in turn
    }
    

    The other way to use /g is in list context:

    my @results = $str =~ /pattern/g; # collect each occurence of 'pattern' within $str into @results
    

    If you’re using /g in scalar context and you’re not iterating over it, you’re almost certainly not using it right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kinda oddball, but I was poking around with the GNU assembler today
This is probably basic stuff, but I can't find the clear answer anywhere.. Lets
This is a normalization thing, but I want I have to hold information about
This may be an unusual question, but are there any resources people have come
This is a bit of a long shot, but if anyone can figure it
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This is my first post here and I wanted to get some input from
This is an oddball question I figure. Can I get NHibernate to ask SQL
Sorry if this is on the wrong site ( maybe superuser ) but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.