home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7556 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.1 KB  |  49 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!seunet!enea!sommar
  3. From: sommar@enea.se (Erland Sommarskog)
  4. Subject: Re: Another RE query
  5. Message-ID: <1992Dec19.215441.11676@enea.se>
  6. Organization: Enea Data AB
  7. References: <1992Dec13.150325.9754@enea.se>
  8. Date: Sat, 19 Dec 1992 21:54:41 GMT
  9. Lines: 38
  10.  
  11. A while ago I wrote:
  12. >Basically what I'm writing is a simple text formatter in which
  13. >user-defined strings are converted to escape-sequences for enscript.
  14. >Those strings occurs in pairs to mark start and end of the text
  15. >to be in deviating font. Anyway, innocently I tried something
  16. >like:
  17. >
  18. >    s!${start}((.|\n)*${stop}!${esc}F${ch1}$1${esc}F${ch2}!g
  19. >
  20. >But of course I got bitten if the pair twice in the same paragraph.
  21. >(I read text paragraph by paragraph, a deliberate restriction.) Would
  22. >$stop be guaranteed to be one character long, it would be trivial:
  23. >
  24. >    s!${start}([^${stop}]*)${stop}!${esc}F${ch1}$1${esc}F${ch2}!g
  25. >
  26. >But $start and $stop can be any length, although would only expect
  27. >one or two characters in practice. But two characters is enough to
  28. >kill the idea.
  29.  
  30. Randall Schwartz was quick to tell me that REs won't work, that's
  31. computer science, not Perl. But as I told him, I am writing this
  32. is Perl, not computer science.
  33.  
  34. Anyway, I've come to conclusion that I can actually get what I
  35. want with regular expressions, if I introduce the restriction
  36. that if $start and $stop may only be equal, if they are one character
  37. long. Then I can look at $start and $stop and if they are equal,
  38. I can use the second substitution above - the one with [^${stop}].
  39. If they are not equal, I can simply subsitute them separately,
  40. and ignore what is in between.
  41.  
  42. I'm not certain that this restriction is feasible. I might want
  43. to use equal $start and $stop like //, but surely not $%. (That
  44. would rather be $% and %$.) But if I find that the index and
  45. substr code that I've written - but not yet had the time to test -
  46. is too slow, this might be a path to go.
  47. -- 
  48. Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
  49.