[Templates] "in array" function?

2008-03-05 Thread Chris Petersen
I realize that it's somewhat un-perl, but is there a way to do "in" within TT? It would be nice to keep things clean when I have large lists of things I'm comparing a single variable to in an if-statement. [% IF var == 'foo' || var == 'bar' %] I've tried to use something like: [% IF [ 'foo'

Re: [Templates] "in array" function?

2008-03-05 Thread Josh Rosenbaum
Chris Petersen wrote: > I realize that it's somewhat un-perl, but is there a way to do "in" > within TT? It would be nice to keep things clean when I have large > lists of things I'm comparing a single variable to in an if-statement. > > [% IF var == 'foo' || var == 'bar' %] > > I've tried t

Re: [Templates] "in array" function?

2008-03-05 Thread Andrew Marold
>How about [% IF foo.match('(foo|bar)') %] ? And of course by foo.match I meant var.match. -- Drew Marold - [EMAIL PROTECTED] Perl programmer, bass player, luthier, Gentleman Adventurer Photography: http://www.flickr.com/photos/unstoppabledrew/ Nothing looks worse on your outdoors resume than

Re: [Templates] "in array" function?

2008-03-05 Thread Andrew Marold
How about [% IF foo.match('(foo|bar)') %] ? Drew Chris Petersen wrote: > I realize that it's somewhat un-perl, but is there a way to do "in" > within TT? It would be nice to keep things clean when I have large > lists of things I'm comparing a single variable to in an if-statement. >

Re: [Templates] "in array" function?

2008-03-05 Thread Chris Petersen
On Mar 5, 2008, at 12:40 PM, Andrew Marold wrote: > How about [% IF foo.match('(foo|bar)') %] ? That would work, assuming you added anchors to the regex and I'm only ever matching against static lists and not pre-defined variables (which in this case is the likely scenario).. but would also r

Re: [Templates] "in array" function?

2008-03-05 Thread Sean McAfee
On Wed, Mar 5, 2008 at 2:46 PM, Chris Petersen <[EMAIL PROTECTED]> wrote: > On Mar 5, 2008, at 12:40 PM, Andrew Marold wrote: > > How about [% IF foo.match('(foo|bar)') %] ? > > That would work, assuming you added anchors to the regex and I'm only > ever matching against static lists and not pre-d

Re: [Templates] "in array" function?

2008-03-06 Thread Slaven Rezic
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_

Re: [Templates] "in array" function?

2008-03-06 Thread Dave Howorth
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;

Re: [Templates] "in array" function?

2008-03-06 Thread Mark Mills
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 Per

Re: [Templates] "in array" function?

2008-03-06 Thread Slaven Rezic
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 l