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:
I think it's little used because there's not much call for it in well-designed code. Trinary is a borrowing from C.$invert ? ($true, $false) : ($false, $true) = (0, 1);
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: searching 2 arrays
by sauoq (Abbot) on Oct 19, 2005 at 16:30 UTC | |
|
Re^2: searching 2 arrays
by Anonymous Monk on Oct 19, 2005 at 13:24 UTC | |
by VSarkiss (Monsignor) on Oct 19, 2005 at 14:41 UTC |