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

  1. Path: sparky!uunet!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!corax.udac.uu.se!irfu.se!jhd
  2. From: jhd@irfu.se (Jan D.)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: stupid questions : deleted ing leading spaces
  5. Message-ID: <1992Sep7.062649.20540@irfu.se>
  6. Date: 7 Sep 92 06:26:49 GMT
  7. References: <1992Sep7.022351.1137@unilabs.uucp>
  8. Organization: Swedish Institute of Space Physics, Uppsala, Sweden
  9. Lines: 33
  10.  
  11. In article <1992Sep7.022351.1137@unilabs.uucp> chare@unilabs.uucp (Chris Hare) writes:
  12. >This is stupid.
  13. >
  14. >I am running 4.035 and I need to delete a single leading space at the
  15. >beginning of a line.
  16. >
  17. >I would have thought that 
  18. >
  19. >         tr/^ //;
  20. >
  21. >would have worked since the line is in $_.
  22. >
  23. >But alas, it doesn't.  There are other spaces in the line, but I don't want
  24. >them affected.
  25.  
  26. I think you are confusing tr// and s// here. s/^ // works.
  27.  
  28. >
  29. >As a matter of ofact, if you can suggest a way to remove the leading
  30. >spaces, and compact multiple spaces any where else on the line to be one
  31. >space I'd appreciate it.
  32. >
  33.  
  34.     s/^ //;
  35.     s/ +/ /g;
  36.  
  37. If you want to replace general white space (i.e. tabs and space) you should say
  38.  
  39.     s/^\s//;
  40.     s/\s+/ /g;
  41.  
  42.  
  43.     Jan D.
  44.