Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!chx400!sicsun!sic!brossard From: brossard@sic.epfl.ch (Alain Brossard EPFL-SIC/SII) Newsgroups: comp.lang.perl Subject: Re: Returning two lists Message-ID: <1991Apr5.182305@sic.epfl.ch> Date: 5 Apr 91 16:23:05 GMT References: <6010@male.EBay.Sun.COM> Sender: news@sicsun.epfl.ch Reply-To: brossard@sasun1.epfl.ch Organization: Ecole Polytechnique Federale de Lausanne Lines: 50 In article <6010@male.EBay.Sun.COM>, me@anywhere.EBay.Sun.COM (Wayne Thompson - IR Workstation Support SE) writes: |> --- Alain Brossard writes --- |> I want to return two lists from a subroutine |> |> sub search { |> local( @list, @whiteouts ) = @_; |> (...) |> return ( @list, @whiteouts ); |> # also tried |> # return ( (@list), (@whiteouts) ); |> } |> |> (@list, @whiteouts) = do search( $dir, '' ); |> |> The only thing I get is that on return, @list |> always contains the union of the returned lists. |> ----------------------------- > > You could return enough information to decompose the lists... > > return (scalar(@list), @list, @whiteouts); Will scalar(ARRAY) always return the size of the array? I didn't see that documented anywhere. > Then recompose them on receipt... > > @_ &search(....); > @whiteouts = splice (@_, shift (@_)); > @list = @_; > > Wayne Thanks for pointing me out the splice fonction. I think the following code is a bit more efficient? @whiteouts = do search( $dir, '' ); @list = splice( @whiteouts, 0, shift(@whiteouts)); @list can be potentialy huge, so I was really looking for the optimal way of doing this. The best way would be to (shudder) use global variables, but this is out since the subroutine is recursive (and not tail-end recursive). -- Alain Brossard, Ecole Polytechnique Federale de Lausanne, SIC/SII, EL-Ecublens, CH-1015 Lausanne, Suisse brossard@sasun1.epfl.ch