Extract multiple value with delimiters from a string

Hi All,

I have a simple perl script that can extract the source code from a webpage like below:

#!/usr/local/bin/perl

use WWW::Mechanize;

my $page = WWW::Mechanize->new();
#$page->get("http://www.hkjc.com/english/racing/selecthorsebychar.asp?ordertype=B");
$page->get("http://www.hkjc.com/chinese/racing/selecthorsebychar.asp?ordertype=2");
my $data = $page->res()->content();
print $data;

What actually in the $data is a single string that contain some data that are useful for me:

What I need to is extract the information of

HorseNo=T108
HorseNo=T252
.......


Please send me your revised perl code for the task.

Thank you,

David
tindavidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
Need to see the entire string
To see whether there is a separator, is the sata as it is represented one entry per line?
0
wilcoxonCommented:
As arnold said, you don't provide us with enough $data to construct a good regex (or other means of extraction).
0
tindavidAuthor Commented:
I don't understand, you mean the data from get() is not good enough for program to extract data after a pattern of "
horse.asp?HorseNo", all I need is the T322, T323, T340 .....


If you cut and paste the perl code and run it you should see the output ,  the value in the data is come from the get("http://www.hkjc.com/chinese/racing/selecthorsebychar.asp?ordertype=2");


 what I want is to continue the code :  print $data

to search $data to extract all information from the $data

.......class=table_Text><a href="horse.asp?HorseNo=T322" ......
.......class=table_Text><a href="horse.asp?HorseNo=T333" ......
.......class=table_Text><a href="horse.asp?HorseNo=T340"........
0
wilcoxonCommented:
It's not the data from the call as much as what data exactly you want extracted...

Is it always href="horse.asp?HorseNo=Txxx"?

Do you want HorseNo=Txxx or just Txxx (your original question said the former but this response sounds like the latter)?

This should at least be a good start...
#!/usr/local/bin/perl
use strict;
use warnings;
use WWW::Mechanize;

my $page = WWW::Mechanize->new();
$page->get("http://www.hkjc.com/chinese/racing/selecthorsebychar.asp?ordertype=2");
my $data = $page->res()->content();
my @horses = $data =~ m{\shref="horse.asp\?HorseNo=(T\d+)"}g;
print join("\n", @horses), "\n";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.