Mark Mills wrote:
> Slaven Rezic wrote:
>> 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 } @_;
>>   }
>>   
> "first" returns the object being searched for and not a true/false 
> value. Searching for 0 might be a problem there...
>
Then it should probably be

   return defined first { $_ eq $str } @_;

It still cannot handle undef values.

(Hmmm, have to go through my code using this construct...)

And it's in List::Util, not Scalar::Util of course.



_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to