Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!male!anywhere.EBay.Sun.COM!me From: me@anywhere.EBay.Sun.COM (Wayne Thompson - IR Workstation Support SE) Newsgroups: comp.lang.perl Subject: Re: Returning two lists Message-ID: <6088@male.EBay.Sun.COM> Date: 6 Apr 91 12:45:51 GMT Sender: news@male.EBay.Sun.COM Lines: 58 From pg 73 of the book "...the value of an array in a scalar context is the length of the array" Yes, your's is more efficient. Hope that helps. Wayne In article <1991Apr5.182305@sic.epfl.ch>, brossard@sic.epfl.ch (Alain Brossard EPFL-SIC/SII) writes: | 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