CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Perl pattern matching


New User

Nov 9, 2014, 11:18 PM

Post #1 of 2 (1988 views)
Perl pattern matching Can't Post

I have a question on perl pattern matching.. I am reading the following 2 lines from the file..
//First line
<td class="offset">0x5300040<br/>-<br/>0x530099C
//second line
<td class="span4" colspan="4"> <a href="cdu_rf_addr_table.htm"><b>CDU</b></a>

My requirement is, when i read the first line, i should get the hex value 0x5300040 and when i read the second line, I should get the string 'CDU'.

Can you please let me know how to do this? I am a beginner on perl programming..

Veteran / Moderator

Nov 10, 2014, 2:14 AM

Post #2 of 2 (1985 views)
Re: [surisingh] Perl pattern matching [In reply to] Can't Post

You should probably use one of the HTML parsers on the CPAN, such as

Otherwise, you give an example, but you don't specify well enough what you are looking for, i.e. I can tell you how to get the data you're looking for in the example you supply, but there will be no guarantee that it will work for other lines where you want to do the same, because I have no idea what the other lines will look like.

This would most probably work for your specific examples:

my ($hex, $str); 
while (<$infile>) '
$hex = $1 if m{<td class="offset">(0x\d+)<br/>};
$str = $1 if m{<b>(\w+)</b>};

but it might fail on other similar lines, because my assumptions about what your data looks like may very well be wrong.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives