[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] About s/foo/bar/x



At 09.31 -0500 1999.02.26, Richard Gordon wrote:
>However, when I use this, regexen that were working fine suddenly go blind and
>it appears to me that whitespace is also being ignored in the target text.

What do you mean "target text"?  Whitespace is ignored in the match,
period, unless it is noted specially.

>have I just completely misunderstood this and, if I have, what possible use is
>the x switch if it is going to alter MacPerl's behavior in dealing with
>something as prevalent and wildly varying as white space?

Well, you don't necessarily use it if you have a lot of whitespace.  :)
However, this may do what you want:

  $_ = 'foo bar  foo baz  foo buz';
  s/(foo\ bar)\ {2}  # add
     foo\ baz\ {2}   # some
    (foo\ buz)       # comments
    /$2 $1/gsx;
  print;

Note that each space is escaped.  I can then add things like +, *, ?, {n,m}
after the space.  You could also use the octal or hex sequence, or
predefine variables to use.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org