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

  • Home
  • SEARCH
  • 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 1043263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:38:22+00:00 2026-05-16T15:38:22+00:00

@urls= $field =~ /<a.*?href=(.*?).*?>.*?<\/a>/mgo; #multi-line, global, compile-once @text= $field =~ /<a.*?href=.*?.*?>(.*?)<\/a>/mgo; for ($count=0; $count<(scalar

  • 0
@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";}
  • 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-16T15:38:23+00:00Added an answer on May 16, 2026 at 3:38 pm

    I think you want is:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my @array_of_links;
    
    my $field = <<EOS;
    <a href="foo.html">foo</a>
    <a href="bar.html">bar</a>
    <a href="baz.html">baz</a>
    EOS
    
    #/ this comment is to unconfuse the SO syntax highlighter. 
    
    while ($field =~ m{<a.*?href="(.*?)".*?>(.*?)</a>}g) {
        push @array_of_links, { url => $1, text => $2 };
    }
    
    for my $link (@array_of_links) {
        print qq("$link->{text}" goes to -> "$link->{url}"\n);
    }
    

    The /o regex 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 /m regex 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 for loops are generally not required in Perl 5. The iterating for loop is much better. If you need to know the index into an array, you should use the range operator:

    for my $i (0 .. $#array_of_links) {
        print qq($i. "$array_of_links[$i]{text}" goes to -> "$array_of_links[$i]{url}"\n);
    }
    

    Perl 5 allows you to choose your own delimiters for strings and regexes if you use their general forms (e.g. m// for regexes and qq// 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.

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

Sidebar

Related Questions

I've got legacy URLs like: mysite.com/index2.php?option=com_mtree&task=print&link_id=383&Itemid=168 and I'd like to redirect any URL that
I am using asp:image field to get an image from different urls. I use
I have a table that contains thousands of URLs. Each URL will have a
I have a TinyMCE field initialized as follows: ... extended_valid_elements: ul[type],li,a[name|href|target|title],img[class|src|border|alt|title|hspace|vspace|width|height|align|name|style],hr[class|width|size|noshade],span[class|align|style],iframe[src|class|width|height|name|align],#p/div,strike, force_br_newlines: true, mode
I am trying to insert a description text field into the database. I was
What's the best way to store, index, and lookup text strings (URLs in this
I'm trying to test if for existing URLs in a user form field and
$value = 'http://www.mydomain.com/this-is-page-one' I have a field in my mysql table called urls which
In the screenshot below is an Entity (URL) in my model. The ParentId field
I'm trying to search a field in a database to extract URLs. Sometimes there

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.