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 8906925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:46:36+00:00 2026-06-15T02:46:36+00:00

I am not an expert in Perl but I have written a Perl script

  • 0

I am not an expert in Perl but I have written a Perl script to parse an HTML page and filter by all href tags:

The output are as shown below:

href="?Name">Name</a>
href="?Desc">Hourly Details</a>
href="/24x7/2012/11-November/">Data
href="./00:00:00/">00:00:00/</a>
href="./01:00:00/">01:00:00/</a>
href="./02:00:00/">02:00:00/</a>
href="./03:00:00/">03:00:00/</a>
href="./04:00:00/">04:00:00/</a>
href="./05:00:00/">05:00:00/</a>
href="./06:00:00/">06:00:00/</a>
href="./07:00:00/">07:00:00/</a>
href="./08:00:00/">08:00:00/</a>
href="./09:00:00/">09:00:00/</a>
href="./10:00:00/">10:00:00/</a>
href="./11:00:00/">11:00:00/</a>
href="./12:00:00/">12:00:00/</a>
href="./13:00:00/">13:00:00/</a>
href="./14:00:00/">14:00:00/</a>
href="./15:00:00/">15:00:00/</a>
href="./16:00:00/">16:00:00/</a>
href="./17:00:00/">17:00:00/</a>
href="./18:00:00/">18:00:00/</a>
href="./19:00:00/">19:00:00/</a>
href="./20:00:00/">20:00:00/</a>
href="./21:00:00/">21:00:00/</a>
href="./22:00:00/">22:00:00/</a>
href="./23:00:00/">23:00:00/</a>

Now I want to extract values within the href tags from “00:00:00” till “23:00:00” while exclude others. The result value would be added to string having a URL:

http://x.download.com/00:00:00
------URL------------/..href../
..............................
http://x.download.com/23:00:00

However by trying the below code:

foreach (@tag) {
    if (m/href/) {
        if ($_ =~ /"\/24/ && $_ =~ /"\/[0-9]/) {
            my $href  = $_;
            my $start = index($href, "\"");
            my $end   = rindex($href, "\"");
            my $link  = substr($href, $start + 1, $end - $start - 1);
            print "Follow: " . $url . $link . "\n";

        }
    }
}

prints:

Follow: http://x.download.com/24x7/2012/11-November/

What should my regular expression be such that required objective can be achieved?

  • 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-06-15T02:46:37+00:00Added an answer on June 15, 2026 at 2:46 am

    This is done very simply with a regular expression, as shown in the program below. It looks for a string of digits or colons immediately following > (and so looks for the text contents of the element rather the href attribute value as yours does) and captures that string into $1.

    But I would prefer to see the problem solved from start to finish using a proper HTML parser, such as
    HTML::TreeBuilder
    or
    Mojo::DOM.

    use strict;
    use warnings;
    
    my @tag = <DATA>;
    
    foreach (@tag) {
      next unless />([\d:]+)/;
      print "http://x.download.com/$1\n";
    }
    
    __DATA__
    href="?Name">Name</a>
    href="?Desc">Hourly Details</a>
    href="/24x7/2012/11-November/">Data
    href="./00:00:00/">00:00:00/</a>
    href="./01:00:00/">01:00:00/</a>
    href="./02:00:00/">02:00:00/</a>
    href="./03:00:00/">03:00:00/</a>
    href="./04:00:00/">04:00:00/</a>
    href="./05:00:00/">05:00:00/</a>
    href="./06:00:00/">06:00:00/</a>
    href="./07:00:00/">07:00:00/</a>
    href="./08:00:00/">08:00:00/</a>
    href="./09:00:00/">09:00:00/</a>
    href="./10:00:00/">10:00:00/</a>
    

    output

    http://x.download.com/00:00:00
    http://x.download.com/01:00:00
    http://x.download.com/02:00:00
    http://x.download.com/03:00:00
    http://x.download.com/04:00:00
    http://x.download.com/05:00:00
    http://x.download.com/06:00:00
    http://x.download.com/07:00:00
    http://x.download.com/08:00:00
    http://x.download.com/09:00:00
    http://x.download.com/10:00:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not very expert with Perl, so I preferred to ask you. I have
I am not an expert in Git, but I have seen this done before
I have a perl script written for version 5.6.1 and which has dependencies on
I'm not expert about css menus. But I know basic system to make css
I'm not very expert on how processors work, but one might imagine that it
I have written the following program for automating scp command in perl. #!/usr/bin/expect spawn
I'm a C/C++/Java/Unix geek by trade, but now I have to write a Perl
my perl script is multi threaded and in each thread i have to write
The following Perl syntax replaces OLD with NEW, but not if a digit exists
I have a perl script exist in the follwoing path (/home/Leen/Desktop/Tools/bin/tool.pl) Every time I

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.