in reply to Re: Re: Re: Class::DBI and how to wantarray...
in thread Class::DBI and how to wantarray...

? That one doesn't do all three, it skips out of the "for" loop as soon as it gets a result..

But thanks for the kick in the right direction with your first reply.. it got me scouring my copy of "Programming Perl". I think the closest I'm going to get to what I'm after is:

#!/usr/bin/perl use strict; my @results; (@results = blah('"or1"')) || (@results = blah1('"or2"')) || (@results = blah('"or3"')); print join(':',@results)."\n"; sub blah{ my ($call) = @_; print "$call "; print wantarray ? "wants array" : "wants string"; print "\n"; return; } sub blah1{ my ($call) = @_; print "$call "; print wantarray ? "wants array" : "wants string"; print "\n"; return (1,2,3); } __END__ ]$ perl wantarr.pl "or1" wants array "or2" wants array 1:2:3

(I extended the test a lil to make sure it was doing what I wanted..)

cheers,

J

Replies are listed 'Best First'.
Re^5 Class::DBI and how to wantarray...
by liz (Monsignor) on Aug 03, 2003 at 13:16 UTC
    From your original node: ...I also want to try several slightly different searches and take the results from the first that gets any... which implies to me you don't want to do the other searches as soon as you have a result. I was going from that assumption.

    Liz

      ummm, yes, that's correct. Putting it in the "for" loop lets me "last" out of the loop, skipping everything else in the block. ie

      for (1){ # if we get results, call "last" which ejects us from the block last if @results = blah('"for"'); # same again last if @results = blah('"for"'); @results = blah('"for'); last; # a final last so we don't loop forever if we don't get any re +sults. }

      cheers,

      J