I have an HTML file. I would like to extract certain data/lines/strings and create a hash array using Perl. I have written Perl scripts using regular expressions earlier, but how do I use HTML Perl modules?
-
These are the lines in the file: <td><b>SCORE</b></td><td>WEIGHT</td><td>GOAL</td><td class="alfsrt">NAME</td></tr><tr> <td class="s5 rt"> 59.37</td> <td class="wht">1 </td> <td class="wht">100 </td> <td><a name="tag_ddr3ctrl_top.T0::ddr3ctrl_coverage::inputs"></a> <a href="grp0.html" >ddr3ctrl_top.T0::ddr3ctrl_coverage::inputs</a></td> </tr><tr> <td class="s7 rt"> 78.32</td> <td class="wht">1 </td> <td class="wht">100 </td> <td><a name="tag_ddr3ctrl_top.T0::ddr3ctrl_coverage::outputs"></a> <a href="grp1.html" >ddr3ctrl_top.T0::ddr3ctrl_coverage::outputs</a></td> I want to extract the following by parsing the file: 1) s5, grp0.html, inputs 2) s7, grp1.html, outputs
-
Answer:
The most reliable way I know of is to have https://metacpan.org/pod/HTML::TreeBuilder parse your file, which will then give you an object containing an HTML Tree, which you can navigate with the methods documented for https://metacpan.org/pod/HTML::Element. It will take a bit to learn the API and how to use it effectively, but https://metacpan.org/pod/distribution/HTML-Tree/lib/HTML/Tree/AboutTrees.pod and https://metacpan.org/pod/distribution/HTML-Tree/lib/HTML/Tree/Scanning.pod will provide some guidance.
Christian Walde at Quora Visit the source
Related Q & A:
- How can I allow user to create posts in website using ASP.NET?Best solution by Programmers
- How to create a Restful web service in .Net Using MySQL?Best solution by stackoverflow.com
- What is Hash Table, how to create a hash table?Best solution by Stack Overflow
- How do I create a digital signature and how do I use it?Best solution by support.office.com
- How to convert a HTML file to XML file?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.