[comp.lang.perl] need help with rexpr

dave@aspect.UUCP (Dave Corcoran) (02/23/91)

printf("hello world\n");

I need to parse an input stream:

	"" "one or more words" "more words" "still more words" 
	"wo rd s" "having fun" "wish you were here" ""
	"" "note that the first or" "last fields may be" "null" 

What I need is each quoted string put in a variable with the quotes
removed, akin to what the shell does with arguments.

To wit:
where foo contains:

	echo $2

when executed thus:

	sh foo "one two" "three four"

yields

	three four

I have toyed with this and have not been able to come up with the
right combination. Any help is apreciated.
-- 
David Corcoran		      -@@
uunet!aspect!dave	        ~
In a society where anything goes eventually everything will.

ejk@ux2.cso.uiuc.edu (Ed Kubaitis - CSO ) (02/23/91)

This seems to work (at least with the sample data you provided):

while (<>) {
   chop; @vars = split(/\s+"/); for(@vars) { s/"//g; }
   < refer to $var[0], $var[1],..., $var[$#var] >
   }

----------------------------------
Ed Kubaitis (ejk@uxh.cso.uiuc.edu)
Computing Services Office - University of Illinois, Urbana