Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: $nextline not working

by davido (Cardinal)
on Mar 22, 2013 at 04:17 UTC ( #1024867=note: print w/replies, xml ) Need Help??

in reply to $nextline not working

"Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems."

-- Jamie Zaqinski

"You cannot parse [X]HTML with regex."

-- bobince on StackOverflow

I saw this coming with the previous question, and had a response typed, but then thought perhaps I should not come down so strong against the practice. But since my fears have begun to play out, I'll post the gist of what I was going to say before:

Regular Expressions are not an ideal tool for parsing HTML. In the trivial cases, everything will seem to work out fine. But then you'll discover that your problem isn't as trivial as it first appeared, and consequently you will come back here to ask how to further refine (or expand) the capability of the regular expressions you're using. This cycle will repeat until eventually you've got a big nasty unmaintainable, fragile heap of regular expressions that stops working every time you look away. Your time will be wasted trying to fix the HTML parsing code, when it really ought to be spent on something more interesting that hasn't already been solved before, robustly, maintainably, and cleanly.

Look at Mojo::DOM, HTML::Parser::Simple, or HTML::Parser. I prefer the former; it's just so darn easy to use. You will spend an hour or two getting accustomed to using whichever of these tools you settle upon, and will save many hours of headaches as a result.

Abandon the notion that your problem is simple enough to just throw a few regexes at it. Simplicity is elusive, and more so when you introduce regular expressions to a non-regular task.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024867]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2019-11-12 21:13 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (66 votes). Check out past polls.