FFRANK has asked for the wisdom of the Perl Monks concerning the following question:
Using PDL, there is a conflict with using List::MoreUtils (any) because PDL has already an "any". Prototype mismatch: sub main::any: none vs (&@) at Exporter.pm(...).
Eg: catch $d where any $c (@c) $a is defined at index $c.
The any sub in List::MoreUtils looks like:#!/usr/bin/perl -w use strict; use PDL; use List::MoreUtils qw(any); my @a; $a[5] = 1; my @b = (0..8); LOOK: for my $d (0..2) { my @c = @b[$d*3..$d*3+2]; if (any { defined $a[$_] } @c) { print "d:$d\n" and last LOOK; } else {();} }
But adding this sub returns an error message. Can't find the way to modify the sub...sub any (&@) { my $f = shift; return if ! @_; for (@_) { return 1 if $f->(); } return 0; }
Also, is this subroutine optimal (does it looks all elements in the array or does it stops rightaway when the "any" condition is met) ?
Thanks very much for comments and hints, best.
FFrank
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sub any
by kyle (Abbot) on Oct 31, 2007 at 18:24 UTC | |
|
Re: sub any
by ikegami (Patriarch) on Nov 01, 2007 at 06:31 UTC | |
by will_ (Scribe) on Apr 25, 2013 at 13:19 UTC |