Newsgroups: comp.lang.perl Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!news From: flee@cs.psu.edu (Felix Lee) Subject: Re: two perl questions Message-ID: <$&bHr-=p@cs.psu.edu> Sender: news@cs.psu.edu (Usenet) Nntp-Posting-Host: dictionopolis.cs.psu.edu Organization: Penn State Computer Science References: <1991Jun7.163638.7834@iWarp.intel.com> Date: Sat, 8 Jun 1991 04:13:50 GMT Lines: 31 >Array can be forced by putting it into a list, or by assigning into >an array. "putting it into a list" is not quite enough. Perl has the real problem that lists are indistinguishable from the comma operator. $x = (5, 10); print "$x\n"; $x = @x = (5, 10); print "$x\n"; What if you want the last word from a split()? This: $x = split(' ', 'a b c'); returns the number of split items. This: @x = split(' ', 'a b c'); $x = $x[$#x]; works, but requires a temporary array. Do you think this works? $x = (0, split(' ', 'a b c')); How about this? sub i1 { @_; } $x = &i1(split(' ', 'a b c')); And this? sub i2 { return @_; } $x = &i2(split(' ', 'a b c')); Do you understand the difference between &i1 and &i2? I certainly don't. Let's hear it for experimental programming. -- Felix Lee flee@cs.psu.edu