|Think about Loose Coupling|
Link Parser, something to be desired?by koolgirl (Hermit)
|on May 29, 2009 at 21:09 UTC||Need Help??|
koolgirl has asked for the wisdom of the Perl Monks concerning the following question:
Hello Fellow Monks,
Long time since I've posted, lo and behold this time I have a question dealing with an actual program I've been asked to write, rather than an exercise. I'm writing a parser to take any random web page, and deaden all the links. This is the code:
On this line:
I originally had
But that would leave certain links unchanged. Mind you, my original regex catches everything I'm looking for, I think, however this substitution operator was my problem, and I ended up having to put the original expression in place of the variable that contained the match. Theoretically this makes no sense to me, and I'm thinking if I understood the reason behind this I might better understand the problem I had.
Also, please note, I saved the before and after of all the matches for later code I need to put together, not just to waste memory ;). Anyway, can anyone explain why I couldn't use $match in the line I pointed out? I'm not trying to get anyone to do my work for me, I'm only trying to understand what the problem was I just created a hack to fix.Thanks :)
UPDATE:Thanks everyone for your very helpful replies, through which I have gained some great resources both for this project and future parsing projects. I would like to make one quick point, however, it turns out that this really is just a quick "one-off" (which YourMother pointed out as a slight possibility), so it wasn't really necessary to be dealing with a module, it isn't a program I'm planning to maintain for a long period of time, just something I wanted to be able to do quickly for a live application demo, something I could verify easily with my own two eyes, and also something that while perhaps better done with an alternative method, it is certainly enhancing my Perl skills, programming skills and introducing me to the world of parsing, therefore being more beneficial for me, in the long run, to do it in this manner, rather than those mentioned, IMHO, of course.
That being said, I am nonetheless planning to go and explore all of the modules mentioned by my fellow monks, momentarily much farther advanced in the Force (or rather, the Source) than myself, expanding the learning aspect of this project to even greater limits, so as I said in the beginning, Thank You very much to all of the monks who have taken their very precious time and effort to offer me a push in the right direction ;) ( also, fixed a typo )