in reply to Re: scanning hash
in thread scanning hash
That works, is brief, and hip. It is possibly not however the most efficient solution as it fails to utilize an iterative, fail fast approach and requires generating and manipulating un-used anon data stuctures. Given the task we can look at less of the hash if we simply fail fast as soon as we detect a non matching value. Depending on the context this may or may not matter. Still a very cool solution though. Wish I had of thought of it. What the hell, I will next time :-)
print ident( { foo=>1, bar=>1, baz=>1 } ); sub ident { my $value = (values %{$_[0]})[0]; for (values %{$_[0]} ) { return 0 unless $value eq $_; } return 1; }
cheers
tachyon
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: scanning hash
by Aristotle (Chancellor) on Aug 01, 2004 at 14:56 UTC | |
by bageler (Hermit) on Aug 01, 2004 at 15:06 UTC | |
by Aristotle (Chancellor) on Aug 01, 2004 at 15:09 UTC |
In Section
Seekers of Perl Wisdom