Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!nsc!taux01!tasu8c!arielf From: arielf@tasu8c.UUCP (Ariel Faigon) Newsgroups: comp.lang.perl Subject: Re: split() Summary: split wants a string Keywords: split list scalar Message-ID: <5769@taux01.nsc.com> Date: 22 Apr 91 13:46:12 GMT References: Sender: netnews@taux01.nsc.com Reply-To: arielf@taux01.nsc.com (Ariel Faigon) Organization: National Semiconductor (IC) Ltd, Israel Lines: 29 +--- In subbarao@phoenix (Kartik Subbarao) says: | Why do I have to say this in perl: | | @foo = split(/[ ,]+/, join(' ', @ARGV)); | | When all I just want to say is: | | @foo = splif(/[ ,]+/, @ARGV); | | what I get in the second instance is the scalar number of things that were | split, rather than the actual split items....Am I misinterpreting what | split does? +--- Welcome to the context sensitive club ;-) split converts a string (scalar) to a list (just like the similar 'unpack' function.) It thus expects a scalar as its second argument. Thus the second argument, the list @ARGV, is evaluated in a scalar-context. A list in a scalar-context returns the number of elements in the list. To recap the list<->scalar conversion functions: 'split' and 'unpack' expect a list and return a scalar their counterparts: 'join' and 'pack' expect a scalar and return a list Ariel Faigon, FAX group, NSTA National Semiconductor (Israel) 6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel Tel. (972)52-522272 arielf@taux01.nsc.com @{hplabs,pyramid,sun,decwrl} 34 48 E / 32 10 N