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

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!s5!is1.is.morgan.com!is0!chetal
  3. From: chetal@is.morgan.com (Pradeep Chetal)
  4. Subject: Re: PERL PARSING
  5. In-Reply-To: holger@is.morgan.com's message of Tue, 15 Dec 1992 22:20:48 GMT
  6. Message-ID: <CHETAL.92Dec15194638@poundcake.is.morgan.com>
  7. Sender: news@is.morgan.com
  8. Nntp-Posting-Host: poundcake
  9. Organization: Information Services, Morgan Stanley, NYC
  10. References: <1992Dec15.172048@is.morgan.com>
  11. Date: Tue, 15 Dec 1992 10:46:38 GMT
  12. Lines: 39
  13.  
  14. In article <1992Dec15.172048@is.morgan.com> holger@is.morgan.com (Holger Veith) writes:
  15.  
  16.    What is the best way to parse a string within PERL where I would like it
  17.    to behave sort of like ksh.
  18.  
  19.    I have used the split command by splitting on white space, but I would
  20.    like everything enclosed in quotes to be one string.
  21.  
  22.    ie.
  23.  
  24.    $x='please "help me split" this line';
  25.  
  26.    ->  $a[1]='please'
  27.        $a[2]='help me split'
  28.        $a[3]='this'
  29.        $a[4]='line'
  30.  
  31.  
  32.    Thank you,
  33.  
  34.    Holger.
  35.  
  36.  
  37. require "shellwords.pl";
  38. $x='Please "help me split" this line';
  39. @X=&shellwords($x);
  40. print "X[0]=$X[0],X[1]=$X[1]\n";
  41.  
  42.  
  43. /Pradeep
  44. --
  45. ----------------------------------------------------------------------------
  46. Pradeep Chetal        UUCP:    ...!uunet!is.morgan.com!chetal
  47. Morgan Stanley        Internet:     chetal@is.morgan.com
  48. 1633 Broadway,        Phone:        (212) 703-2220 (O)
  49. NY, NY 10019                (212) 703-2371 (FAX)
  50.             _______________    __o
  51.         _________________     -\<,
  52.                         ......O/ O
  53.