Path: utzoo!attcan!uunet!ogicse!caesar.cs.montana.edu!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!apple!sun-barr!newstop!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: @array in scalar context Keywords: array grep scalar APL Message-ID: <100271@convex.convex.com> Date: 26 Feb 90 20:44:46 GMT References: <7165@jpl-devvax.JPL.NASA.GOV> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: comp Organization: CONVEX Software Development, Richardson, TX Lines: 41 In article <7165@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >Does anyone actually use this to get at the last value of an array? If not, >we could easily change it to return the number of elements in the array. > > print "ok\n" if @array == $#array - $[ + 1; Well, when I was young and foolish :-), I used to do this @foo = <*.*>; next if @foo =~ /\*/; to check for no match on the glob. Now wish the csh doing my globbing, @foo isn't set on no match (which I like), and I get a coredump (which I don't much care for. :-). The question is: what does @array do in a scalar context? Larry proposes to set it true if the array is not empty. If this is done, I'd like to see a warning or error if it's used in a way that this doesn't make sense, as in: @foo = 7; @foo =~ s/foo/bar; if (@foo =~ /something) Of course, what I'd like better would be more work: a scalar reference to an array is the same as the same scalar reference to each element of the array. But along that road lies madness and APL, eh? On arrays in scalar contexts, why doesn't this give any output: @a = ( 'red', 'yellow', 'green'); print "has low\n" if grep(/low/,@a); If I assign the grep to @b, I get the expected element 'yellow'. --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in : Editor too big!"