[lug] XEmacs quoting madness!

Tkil tkil at scrye.com
Mon Aug 20 16:17:48 MDT 2001


just by way of comparison... given the emacs snippit in one of my
messages:

| (while (re-search-forward 
|         (concat "^\\\""           ; beginning of line + initial quote
|                 "\\([^\\\"]+\\)"  ; software bit
|                 "[\\\",]+"        ; intervening commas and quotes
|                 "\\([^\\\"]+\\)"  ; description
|                 ".*$")            ; rest of line.
|         (point-max) t) ;
|   (replace-match (concat "part=\\1\n"
|                          "  description=\\2\n"))))))

i thought it'd be interesting to do a perl version of it:

| s/^"([^"]+)[",]+([^"]+).*$/part=$1\n  description=$2\n/g;

a relatively recent addition to perl allows you to comment a regex
pattern, which is nice:

| s/^"          # beginning of line + initial quote
|   ([^"]+)     # software bit
|   [",]+       # intervening commas and quotes
|   ([^"]+)     # description
|   .*$         # rest of line
|  /part=$1\n  description=$2\n/gx;

this becomes particularly helpful when the patterns get out of
control.  here's a snippit from a cheesy HTML parser i wrote (when i
was in a situation where i couldn't install HTML::Parser from CPAN):

| if ($t =~ m{\G
|       (                   # (whole thing is in $1)
|        <([^/]\w*)         # start of tag ($2)
|        \s*
|        ((?:               # attribute list ($3)
|          (?:[^>\s=]+      #   the attribute itself
|           (?:\s*=\s*      #   maybe followed by an equals sign and
|            (?:\"[^\"]*\"| #     double-quoted, or
|             \'[^\']*\'|   #     single-quoted, or
|             [^>\s]+)      #     plain value
|           )?              #   or maybe not.
|           \s*             #   and a bit of whitespace
|          ))*)             # we can have 0 or more attributes
|        \s*>)}gcx)

lots more fun and loving in "perldoc perlre".  

anyway.  back to work...

t.



More information about the LUG mailing list