Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

How to Deflea a Cat

by Ovid (Cardinal)
on Aug 28, 2003 at 15:54 UTC ( #287419=note: print w/replies, xml ) Need Help??

in reply to Regexp and HTML revisited...
in thread Regexps to change HTML tags/attributes

Tricky wrote:

In reply to Ovid and Abigail's comments : the TokeParser module is a great idea, the problem is that my remit is to investigate how regexps can be applied to reformatting HTML pages. I have a regexp for a background colour attribute, though the '#' character treats all characters following as a comment!

I'm not sure what you mean by your statement that your "remit is to investigate how regexps can be applied to reformatting HTML pages". If, by that, you mean that someone else has tasked you with this, then they have made a mistake. If someone comes to me and says "Ovid, I need you to deflea my cat. Here, use this shotgun", then I know that person made a mistake that's all too common in business. In short, the mistake is to say "here's a solution, let's see how we can make it fit our problem." That's absolutely the wrong way to go about things.

Mind you, it's an easy thing to do. I suspect that cyanide kills fleas. Therefore, I might ask a friend "how can I use cyanide to deflea my cat?" When that friend tells me to use flea powder, my first instinct shouldn't be "but I've got all of this cyanide handy, how do I use that?" Instead, a better tactic is to revisit the original problem. How do I remove the fleas from my HTML ... er ... cat? If the proposed solution is better than mine, I should be willing to swallow my pride and go with the best solution. Heck, if all politicians believed that, we'd have a much better country :)

Just for giggles, let's look at some valid HTML tags:

<a href="foobar.txt" onclick="javascript:go_boom()">stuph</a> <A HREF =foobar.txt ONCLICK='javascript:go_boom()'>stuph</a> <A HREF = 'foobar.txt' ONCLICK= 'javascript:go_boom()' > stuph </a > <font color="#FAFA519">test</font> <font color="FAFA519">test</font> <font color="fafa519">test</font> <font color=fafa519>test</font> <font color='fafa519'>test</font> <font color=fafa519 >test</font>

Do you like all of those font tags? Most browsers will render all of them identically. That's a great example of why most regular expressions will fail. They're tough to write.

But just to show you that I'm a good sport about how to deflea your cat, here's a link to Tom Christiansen's article, HTML Hacking with Regular Expressions. Enjoy!


New address of my CGI Course.

Replies are listed 'Best First'.
Re: How to Deflea a Cat
by BrowserUk (Patriarch) on Aug 29, 2003 at 12:39 UTC

    Cat Bathing As A Martial Art

    Some people say cats never have to be bathed. They say cats lick themselves clean. They say cats have a special enzyme of some sort in their saliva that works like new, improved Wisk - dislodging the dirt where it hides and whisking it away.

    I've spent most of my life believing this folklore. Like most blind believers, I've been able to discount all the facts to the contrary, the kitty odours that lurk in the corners of the garage and dirt smudges that cling to the throw rug by the fireplace.

    The time comes, however, when a man must face reality: when he must look squarely in the face of massive public sentiment to the contrary and announce: "This cat smells like a port-a-potty on a hot day in Juarez."

    When that day arrives at your house, as it has in mine, I have some advice you might consider as you place your feline friend under your arm and head for the bathtub:

    Know that although the cat has the advantage of quickness and lack of concern for human life, you have the advantage of strength. Capitalize on that advantage by selecting the battlefield. Don't try to bathe him in an open area where he can force you to chase him. Pick a very small bathroom. If your bathroom is more than four feet square, I recommend that you get in the tub with the cat and close the sliding-glass doors as if you were about to take a shower. (A simple shower curtain will not do. A berserk cat can shred a three-ply rubber shower curtain quicker than a politician can shift positions.)

    Know that a cat has claws and will not hesitate to remove all the skin from your body. Your advantage here is that you are smart and know how to dress to protect yourself. I recommend canvas overalls tucked into high-top construction boots, a pair of steel-mesh gloves, an army helmet, a hockey face mask, and a long-sleeved flak jacket. Prepare everything in advance. There is no time to go out for a towel when you have a cat digging a hole in your flak jacket. Draw the water. Make sure the bottle of kitty shampoo is inside the glass enclosure. Make sure the towel can be reached, even if you are lying on your back in the water.

    Use the element of surprise. Pick up your cat nonchalantly, as if to simply carry him to his supper dish. (Cats will not usually notice your strange attire. They have little or no interest in fashion as a rule. If he does notice your garb, calmly explain that you are taking part in a product testing experiment for J.C. Penney.)

    Once you are inside the bathroom, speed is essential to survival. In a single liquid motion, shut the bathroom door, step into the tub enclosure, slide the glass door shut, dip the cat in the water and squirt him with shampoo. You have begun one of the wildest 45 seconds of your life.

    Cats have no handles. Add the fact that he now has soapy fur, and the problem is radically compounded. Do not expect to hold on to him for more than two or three seconds at a time. When you have him, however, you must remember to give him another squirt of shampoo and rub like crazy. He'll then spring free and fall back into the water, thereby rinsing himself off. (The national record for cats is three latherings, so don't expect too much.)

    Next, the cat must be dried. Novice cat bathers always assume this part will be the most difficult, for humans generally are worn out at this point and the cat is just getting really determined. In fact, the drying is simple compared to what you have just been through. That's because by now the cat is semipermanently affixed to your right leg. You simply pop the drain plug with your foot, reach for your towel and wait. (Occasionally, however, the cat will end up clinging to the top of your army helmet. If this happens, the best thing you can do is to shake him loose and to encourage him toward your leg.) After all the water is drained from the tub, it is a simple matter to just reach down and dry the cat.

    In a few days the cat will relax enough to be removed from your leg. He will usually have nothing to say for about three weeks and will spend a lot of time sitting with his back to you. He might even become psychoceramic and develop the fixed stare of a plaster figurine.

    You will be tempted to assume he is angry. This isn't usually the case. As a rule he is simply plotting ways to get through your defenses and injure you for life the next time you decide to give him a bath.

    But at least now he smells a lot better.

    From off the web somewhere a couple of years ago, attributed to "Stephen Schulze". I have a shortcut to this on my desktop. Very little gets a place on my desktop, but this always renders me to tears and cheers me up no matter how frustrating my computer/compiler/heating system/... is being.

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

Re: How to Deflea a Cat
by dws (Chancellor) on Aug 28, 2003 at 18:36 UTC
    <font color="FAFA519">test</font> ...
    Do you like all of those font tags? Most browsers will render all of them identically.

    I have never, ever run into a font tag like that in the wild. No tools that I know of will generate such tags. They have to be mis-coded by hand. If the corpus you're dealing with is "safe" (e.g., all generated by working tools), then you probably won't need to worry about these at all.

      I'm looking into altering in-line stlyles first, then delving into embedded style sheets next.

      It's laborious and not-a-little pointless, as tried-and-tested HTML parser modules are available. My project aim is to look into the pros and cons of changing HTML with regexps.

      T : )
        Sorry, this doesn't have anything to do with HTML but on how to actually deflea your animals, check out
Re: How to Deflea a Cat
by Tricky (Sexton) on Aug 28, 2003 at 17:42 UTC

    Defleaing a cat with old tactical nukes would seem a little daft(as we say in Yorkshire). Regular expressions do seem to be very...long-winded and difficult, after looking briefly into parse-trees.

    Reinventing nukes and cyanide aside, I'm stuck with this approach for my project, so I'll just have to demonstrate
    the limitations of regexps for this kind of work. Tom Cristiansen's article was informative, and showed me how limited my approach is.

    Still, thanks for the help. Always appreciated.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2023-02-04 12:24 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (31 votes). Check out past polls.