home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / question / 14818 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.1 KB  |  46 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!usc!news.cerf.net!netlabs!lwall
  3. From: lwall@netlabs.com (Larry Wall)
  4. Subject: Re: PERL PARSING
  5. Message-ID: <1992Dec16.213713.23851@netlabs.com>
  6. Sender: news@netlabs.com
  7. Nntp-Posting-Host: scalpel.netlabs.com
  8. Organization: NetLabs, Inc.
  9. References: <1992Dec15.172048@is.morgan.com>
  10. Date: Wed, 16 Dec 1992 21:37:13 GMT
  11. Lines: 33
  12.  
  13. In article <1992Dec15.172048@is.morgan.com> holger@is.morgan.com (Holger Veith) writes:
  14. : What is the best way to parse a string within PERL where I would like it
  15. : to behave sort of like ksh.
  16. : I have used the split command by splitting on white space, but I would
  17. : like everything enclosed in quotes to be one string.
  18. : ie.
  19. : $x='please "help me split" this line';
  20. : ->  $a[1]='please'
  21. :     $a[2]='help me split'
  22. :     $a[3]='this'
  23. :     $a[4]='line'
  24.  
  25. $ perl
  26. require "shellwords.pl";
  27. $x='please "help me split" this line';
  28. @a = &shellwords($x);
  29. $" = "\n"; 
  30. print "@a\n";
  31. __END__
  32. please
  33. help me split
  34. this
  35. line
  36. $
  37.  
  38. Larry Wall
  39. lwall@netlabs.com
  40.  
  41.  
  42.