Well, you're right that you shouldn't parse HTML with regular expressions. And since it is, it probably will not “just work.”
Ideally, you need to use an HTML parsing and processing library. Do not think that HTML is a big line for manipulating text functions: it is a serialized, formatted data structure. You should monkey with him use only the library for this purpose. Various libraries have already fixed hundreds of errors that you are likely to encounter, making it twice as likely that a simple text manipulation procedure written against them will “just work”. Perl programmers at the master level usually don’t parse HTML in this way, and that’s not because they are obsessive and irrational with regard to the quality and cleanliness of the code - because they know that inventing the wheel alone is unlikely to be achieved by the existing mechanism.
I recommend HTML :: Tree because it works the way I think of HTML (and XML). I think there are several other libraries that may be more popular.
The real truth is that if you can’t even compile your program for compilation, you need to invest a little more time (half a day or so), figuring out the basics before coming to seek help. You have a syntax error for using the regex operator s /// g, and you need to figure out how this should work before moving on. It is not difficult, and you can find out what you need from the book of the Camel, or man perlretut, or several other sources. If you don’t know how to debug your program now, then probably any help you get here will simply lead you to the next syntax error that you cannot overcome.
source share