in reply to Re^3: Smartmatch alternatives
in thread Smartmatch alternatives
so this should be a fast and core fallback if no better module available.
DB<125> @a=(0)x10 => (0, 0, 0, 0, 0, 0, 0, 0, 0, 0) DB<126> sub any (&@) { my $cr=shift; defined first { &$cr } @_ } DB<127> any {$_==0} @a => 1
well could be faster if I could avoid '$cr' but my golfing foo is weak today. =)
update
got it :)
DB<138> sub any (&@) { defined &first (shift, @_) } DB<139> any {$_==0} @a => 1
update
better :)
DB<144> sub any (&\@) { defined &first } DB<145> any {$_==0} @a => 1
UPDATE
DARN! still buggy with false positives!
didn't sleep enough...
update
this seems to work...
DB<230> sub any (&@) { my $x=&List::Util::first; defined $x } DB<231> any { $_ eq 0 } @a => "" DB<232> any { $_ eq 5 } @a => 1 DB<233> @a => (1, 2, 3, 4, 5)
Cheers Rolf
( addicted to the Perl Programming Language)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Smartmatch alternatives
by tobyink (Canon) on Dec 17, 2013 at 19:01 UTC | |
by LanX (Saint) on Dec 17, 2013 at 22:08 UTC | |
by LanX (Saint) on Dec 17, 2013 at 22:57 UTC | |
by tobyink (Canon) on Dec 18, 2013 at 00:11 UTC | |
by LanX (Saint) on Dec 18, 2013 at 02:19 UTC | |
by tobyink (Canon) on Dec 18, 2013 at 07:34 UTC | |
|
In Section
Seekers of Perl Wisdom