ok, there's gotta be a right way to do this, but I can't seem to see the forest for the trees..
Using the search method of a Class::DBI subclass, assigning to an array gets you the search results, assigning to a string gets you an iterator.. I want the results, not the iterator. I also want to try several slightly different searches and take the results from the first that gets any..
#!/usr/bin/perl use strict; my @results; # what I thought would work ok.. @results = blah('"or"') || blah('"or"') || blah('"or"'); # an attempt to fix.. @results = (blah('"(or)"')) || (blah('"(or)"')) || (blah('"(or)"')); # an ugly solution that works.. if (@results = blah('"if"')){ } elsif (@results = blah('"if"')) { } elsif (@results = blah('"if"')) { } # not as ugly, but still a hack for (1){ last if @results = blah('"for"'); last if @results = blah('"for"'); last if @results = blah('"for'); last; } sub blah{ my ($call) = @_; print "$call "; print wantarray ? "wants array" : "wants string"; print "\n"; return (1,2,3); } __END__ ]$ perl wantarr.pl "or" wants string "(or)" wants string "if" wants array "for" wants array
As you see I have 2 implementations that work ok, but I'm sure there's got to be a better way.. any suggestions?
cheers,
J
edited by ybiC: retitle from "how to wantarray..." for searchability
In reply to Class::DBI and how to wantarray... by edoc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |