in reply to searching 2 arrays

You can speed that up by making a hash of the reference array and testing for existence of keys.

my %search; @search{@DB} = (); for (@Input) { print exists $search{$_} ? "$_ : Found $_\n" : "$_ : Not Found $_\n"; }

Does your @DB come from a relational database? It may be a better design to let the rdbm do the work by constructing a query on your inputs.

Update: The ?: operator is called the trinary op in perlop. It is like if..else.. but it returns a value, which is what's getting printed here. Syntax is condition ? if-value : else-value. A cool but little-used property of trinary is that it's an lvalue:

$invert ? ($true, $false) : ($false, $true) = (0, 1);
I think it's little used because there's not much call for it in well-designed code. Trinary is a borrowing from C.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: searching 2 arrays
by sauoq (Abbot) on Oct 19, 2005 at 16:30 UTC
    The ?: operator is called the trinary op in perlop.

    Actually—in case anyone searches and can't find it—perlop refers to it as the "ternary" operator. That's probably the more common terminology though "trinary" is a perfectly acceptable alternative. Another alternative is the "conditional" operator. And, sometimes it's called the "tertiary" operator but that's really just incorrect usage.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re^2: searching 2 arrays
by Anonymous Monk on Oct 19, 2005 at 13:24 UTC
    No @DB doesn't come from RDM, I am constructing it.

    Thanks for your help

    But I don't understand/learnt how does the ? : work!