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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:40:16+00:00 2026-05-26T18:40:16+00:00

I have written the following Perl script- use HTML::TreeBuilder; my $html = HTML::TreeBuilder->new_from_content(<<END_HTML); <span

  • 0

I have written the following Perl script-

use HTML::TreeBuilder;

my $html = HTML::TreeBuilder->new_from_content(<<END_HTML);

<span class=time>1 h </span> 
<a href="http://foo.com/User">User</a>: There are not enough <b>big</b>
<b>fish</b> in the lake ;
END_HTML

my $source   = "foo";
my @time     = "10-14-2011";
my $name     = $html->find('a')->as_text;  
my $comment  = $html->as_text;
my @keywords = map { $_->as_text } $html->find('b');

Which outputs- foo, 10-14-2011, User, 1h User: There are not enough big fish in the lake, big fish
Which is perfect and what I wanted from the test html but
this only works fine when I put in the aforementioned HTML, which I did for test purposes.

However the full HTML file has multiple references of ‘a’ and ‘b’ for instances therefore when printing out the results for these columns are blank.

How can I account for multiple values for specific searches?

  • 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-26T18:40:16+00:00Added an answer on May 26, 2026 at 6:40 pm

    Without sight of your real HTML it is hard to help, but $html->find returns a list of <a> elements, so you could write something like

    foreach my $anchor ($html->find('a')) {
      print $anchor->as_text, "\n";
    }
    

    But that will find all <a> elements, and it is unlikely that that is what you want. $html->look_down() is far more flexible, and provides for searching by attribute as well as by tag name.

    I cannot begin to guess about your problem with comments without seeing what data you are dealing with.


    If you need to process each text element independently then you probably need to call the objectify_text method. This turns every text element in the tree into a pseudo element with a ~text tag name and a text attribute, for instance <p>paragraph text</p> would be transformed into <p><~text text="paragraph text" /></p>. These elements can be discovered using $html->find('~text') as normal. Here is some code to demonstrate

    use strict;
    use warnings;
    
    use HTML::TreeBuilder;
    
    my $html = HTML::TreeBuilder->new_from_content(<<END_HTML);
    
    <span class=time>1 h </span> 
    <a href="http://foo.com/User">User</a>: There are not enough <b>big</b>
    <b>fish</b> in the lake ;
    END_HTML
    
    $html->objectify_text;
    print $_->attr('text'), "\n" for $html->find('~text');
    

    OUTPUT

    1 h 
    
    User
    : There are not enough 
    big
    
    fish
     in the lake ; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, I have written a perl script, as the following code: my @files =
I have written following xaml code: <Window x:Class=WpfApplication3.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=200 Width=200> <StackPanel>
I have written the following Utility class to get an instance of any class
I have a ClearQuest API script written in Perl. If I do this: #print
I have written following script in python which works fine: from sys import argv
I have a Perl script that I've written and can compile it using pp
I have written following app.js class to get 3 tabs in my app using
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have written the following constraint for a column I've called 'grade': CONSTRAINT gradeRule
I have written a following code to get just the file name without extension

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.