home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5760 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  1.8 KB

  1. Path: sparky!uunet!news.univie.ac.at!blekul11!frmop11!barilvm!vms.huji.ac.il!wisipc.weizmann.ac.il!menora.weizmann.ac.il
  2.  dov
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: stupid questions : deleted ing leading spaces
  5. Message-ID: <1992Sep7.092151.13593@wisipc.weizmann.ac.il>
  6. From: dov@menora.weizmann.ac.il (Dov Grobgeld)
  7. Date: Mon, 7 Sep 1992 09:21:51 GMT
  8. Sender: news@wisipc.weizmann.ac.il
  9. References: <1992Sep7.022351.1137@unilabs.uucp>
  10. Organization: Weizmann Institute of Science, Computation Center.
  11. Lines: 40
  12.  
  13. chare@unilabs.uucp (Chris Hare) writes:
  14.  
  15. You will probably be swamped with replies, but never mind...
  16.  
  17. : This is stupid.
  18. :
  19. That's a perpetual truth of mankind.
  20.  
  21. : I am running 4.035 and I need to delete a single leading space at the
  22. : beginning of a line.
  23. :
  24. : I would have thought that
  25. :
  26. :          tr/^ //;
  27. :
  28. : would have worked since the line is in $_.
  29. :
  30. You want to use s/'source'/'target'/ which (s)ubstitutes the source to the
  31. target. tr/'list1'/'list2'/ (tr)anslates on a character to character basis
  32. the characters in list1 to the corresponding character in list2. What you
  33. want is
  34.  
  35.            s/^ //;
  36.  
  37. : As a matter of ofact, if you can suggest a way to remove the leading
  38. : spaces, and compact multiple spaces any where else on the line to be one
  39. : space I'd appreciate it.
  40. :
  41.           s/^\s+//;     # Delete leading spaces (including tabs)
  42.           s/ +/ /g;     # Change all (that's the 'g') multiple spaces
  43.                         # to one space
  44.  
  45. --
  46.                                                         ___   ___
  47.                                                       /  o  \   o \
  48. Dov Grobgeld                                         ( o  o  ) o   |
  49. The Weizmann Institute of Science, Israel             \  o  /o  o /
  50. "Where the tree of wisdom carries oranges"              | |   | |
  51.                                                        _| |_ _| |_
  52.  
  53.