[Linux-disciples] Subtitutions of all permutations

Stephen R Laniel linux-disciples@bostoncoop.net
Fri, 19 Sep 2003 14:39:34 -0400


A Perl puzzler for y'all; maybe it's not as difficult as I seem to think
it is:

Suppose you have an HTML tag like the img tag that looks like so:

<img alt="blah" width="blah" src="foo" height="gern" style="geh" />

You want to strip out everything except for the "alt" and the "src", but
they could appear anywhere in the list of attributes. So in Perl

s{<img(.*)alt=(".*") src=(".*")(.*)(/?)>}{<img src=$2 alt=$1 />}g;

would work, but then you'd have to do another version of the same
substitution where the src came first and the alt came second, right?

In greater generality, I guess what I'm wondering is whether there's any
way to say "If there's any permutation of [list of things], perform this
substitution on it." Is there any way to do that?

-- 
```All placebos are not the same,' Eli Lilly spokesman Giles French
   said. `Pacifex is the only placebo that's green and shaped like a
   triangle. Pacifex: A doctor gave it to you.''
  -http://www.theonion.com/3936/news2.html