Newsgroups: comp.lang.perl
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!convex!usenet
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: two perl questions
Message-ID: <1991Jun07.015530.21391@convex.com>
Sender: usenet@convex.com (news access account)
Nntp-Posting-Host: pixel.convex.com
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: CONVEX Software Development, Richardson, TX
References: <JBRYANS.91Jun6175843@beach.csulb.edu>
Date: Fri, 07 Jun 1991 01:55:30 GMT
Lines: 29

From the keyboard of jbryans@beach.csulb.edu (Jack Bryans):
:A while back there was a thread on forcing expression evaluation to be either
:in scalar or array context.  I thought, "sure, I'll remember that".  Sigh!
:What are some ways of forcing expr evaluation in array context?  A FAQ add'n,
:perhaps?

It's not as straight-forward as using a scalar() on your expression, but
that's ok, because usually you don't need it.  Things that want to be in
an array context have no trouble getting there.  The list operators 
supply them, like:

    print /(foo) (bar)/;

If you assign to an array, you get one:

    @ary = /(foo) (bar)/;

You can also build a list and subscript it:

    $x = (/(foo) (bar)/)[$i]; # $i == 0 or 1
    @x = (/(foo) (bar)/)[@i]; # @i == (0,1) or (0,1)

Where would you like to force an array context?


--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
	    "Perl is to sed as C is to assembly language."  -me
