>>>>> "MD" == Michele Dondi <> writes:
MD> On Thu, 05 Apr 2007 10:54:28 -0400, Uri Guttman <>
MD> wrote:
>> and that rebuilds the anon hash each time which is not nice if it is
>> called more than once. maybe in a cgi or single shot script it would be
>> ok.
>>
>> a simple way to make a hash of keys with undef values is:
>>
>> my %isa_foo ;
>> @isa_foo{ @values } = () ;
MD> Yes, yes, yes. I don't feel a *compelling* need for such a beast as
MD> that I hinted to in the other post. But occasionally I miss it.
MD> Precisely when I *want* to check if if a single value is in a list,
MD> and want to do so *only once*, possibly in one *single statement*.
MD> Well, a situation that springs to mind is this: the other day I wanted
MD> to check if a coderef is lvalue'd but attributes::get() returns a list
MD> of the attributes defined on a ref, so I'm exactly under the
MD> circumstances described above. Basically I may want something short
MD> enough to be used as in
MD> if ( islvalued($ref) ) { ... }
then List::Util::first is your friend. building a temp hash from a list
and then looking it up is at least O(N) (more caps!) as it has to scan
all the keys. first is O(N) but will scan on average only half of the
keys.
if ( first { $_ eq 'lvalue' } attributes::get($ref) ) { ... }
the hash test is almost always better when you check it more than
once. and as i said i use it if i have the list of keys in advance since
saying $isa_foo{$key} is nice and readable.
uri
--
Uri Guttman ------
--------
http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org