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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.