Path: utzoo!attcan!uunet!samsung!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: shift( split( ... - bad syntax Message-ID: <10194@jpl-devvax.JPL.NASA.GOV> Date: 31 Oct 90 19:44:09 GMT References: <42583@mips.mips.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 29 In article <42583@mips.mips.COM> bjorn@mips.COM (Bjorn Satdeva - /sys/admin Inc) writes: : Why is the following not legal? : : $OldName = shift( split( '\.', $OldDomain ) ); : : Split is returnning an array. Doing a shift on the result, without : first storing it to a temp variable seems to me it should be a perfectly : legal thing to to. : : What had I misunderstood? Perl differentiates between named arrays and array values, also called lists. A number of operators that alter the state of a list require a named array rather than an array value, since only named arrays can remember state. You can, however, do what you want. Say either of $OldName = (split( /\./, $OldDomain)[0]; # or [$[] or ($OldName) = split( /\./, $OldDomain); The latter is preferred for efficiency, since split to a list is smart about how many fields it actually has to produce. Of course, there's always ($OldName) = /^([^.]*)/; Larry