[Templates] "in array" function?

Slaven Rezic srezic at iconmobile.com
Thu Mar 6 11:38:35 GMT 2008


Dave Howorth wrote:
> Sean McAfee wrote:
>   
>> $Template::Stash::SCALAR_OPS->{isOneOf} = sub {
>>     my $str = shift;
>>     $str eq $_ and return 1 for @_;
>>     return 0;
>> };
>>     
>
> Or for added pzazz, something like:
>
>   use Perl6::Junction qw/ any /;
>
>   $Template::Stash::SCALAR_OPS->{isOneOf} = sub {
>       my $str = shift;
>       return (any(@_) eq $str);
>   }
>
> TMTOWTDI :)
Or the core module Scalar::Util (untested):

use List::Util qw(first);

$Template::Stash::SCALAR_OPS->{isOneOf} = sub {
      my $str = shift;
      return (first { $_ eq $str } @_;
  }





More information about the templates mailing list