[Templates] trueness of arrrays/hashes

2002-01-24 Thread Stas Bekman
I was wondering why it's always a quiz to figure out whether a value is empty or not. let's say I've $var = { array => [], hash => {}, }; in perl I can say do {...} if @{ $var{array} }; do {...} if %{ $var{hash} }; in template toolkit, passing $var to the template (var=>$var), this wo

Re: [Templates] trueness of arrrays/hashes

2002-01-24 Thread darren chamberlain
Casey West <[EMAIL PROTECTED]> said something to this effect on 01/24/2002: > On Thu, Jan 24, 2002 at 06:11:33PM +, Simon Wilcox wrote: > :Should there be a .empty operator that returns true is empty where empty > :means var is either null or undefined ? > > We already have something that *sh

Re: [Templates] trueness of arrrays/hashes

2002-01-26 Thread Stas Bekman
darren chamberlain wrote: > Stas Bekman <[EMAIL PROTECTED]> said something to this effect on 01/25/2002: > >>Andy Wardley wrote: >> >>>Perhaps the best solution is to have a '.size' method which works >>>consistently >>>across all data types: >>> >>> [% item.size %]# 1 >>> [% hash.size %]

Re: [Templates] trueness of arrrays/hashes

2002-01-25 Thread Andy Wardley
On Thu, Jan 24, 2002 at 05:28:59PM -0500, Mark Mills wrote: > [% IF array.defined %] should tell you if something is null or non-existant in the >stashhash. Yep, if 'array' is defined then .defined returns true, even if it's a reference to an empty array or empty hash. > As people have said, D

Re: [Templates] trueness of arrrays/hashes

2002-01-25 Thread Stas Bekman
Andy Wardley wrote: [the reasoning for DWIM not working snipped] > Perhaps the best solution is to have a '.size' method which works consistently > across all data types: > > [% item.size %]# 1 > [% hash.size %]# scalar(keys %$hash) > [% list.size %]# scalar(@$list) +1, not

RE: [Templates] trueness of arrrays/hashes

2002-01-24 Thread Mark Mills
> :> We already have something that *should* do this. .defined(). > :> > :> Just as in Perl, where defined(@foo) will only return true > if @foo has > :> elements. Problem is, array.defined doesn't do this correcty yet. > : > :$ perl -wle 'my @foo = (); print defined @foo' > :defined(@array) i

Re: [Templates] trueness of arrrays/hashes

2002-03-12 Thread Andy Wardley
Andy Wardley wrote: >Perhaps the best solution is to have a '.size' method which works >consistently >across all data types: > > [% item.size %]# 1 > [% hash.size %]# scalar(keys %$hash) > [% list.size %]# scalar(@$list) On Fri, Jan 25, 2002 at 12:38:25PM -0500, darren chamberlai

Re: [Templates] trueness of arrrays/hashes

2002-03-12 Thread Andy Wardley
On Sat, Jan 26, 2002 at 01:51:34PM +0800, Stas Bekman wrote: > IMHO, this is not right. .size for hash and array will show the number > of elements in the datastructure, a scalar always has exactly 1 element > (or we probably can say 0 elements if it's undef). So I'd say: Damn, yes. Sorry. Th

Re: [Templates] trueness of arrrays/hashes

2002-01-28 Thread Craig Barratt
> > As people have said, DWIM sez [% IF array %] should be true only if array > > contains something more than nothing. > > As far as I know, there's no way to do this without re-writing large parts > of TT. Even then, I don't think it's possible. > > The Perl code generated for > > [% IF a

Re: [Templates] trueness of arrrays/hashes

2002-01-24 Thread Casey West
On Thu, Jan 24, 2002 at 03:56:20PM -0500, darren chamberlain wrote: : :Casey West <[EMAIL PROTECTED]> said something to this effect on 01/24/2002: :> On Thu, Jan 24, 2002 at 06:11:33PM +, Simon Wilcox wrote: :> :Should there be a .empty operator that returns true is empty where empty :> :means

RE: [Templates] trueness of arrrays/hashes

2002-01-24 Thread Mark Mills
You know, when I first saw this I thought, "eh, it is like `exists' rather than `defined', he just needs to put on the other pair of perl blinders" but now I'm not so sure. In his example below [% array %] happily dumps something like "ARRAY(0x81c1c88)". If TT2 is just dumping the stringified

Re: [Templates] trueness of arrrays/hashes

2002-01-25 Thread darren chamberlain
Stas Bekman <[EMAIL PROTECTED]> said something to this effect on 01/25/2002: > Andy Wardley wrote: > >Perhaps the best solution is to have a '.size' method which works > >consistently > >across all data types: > > > > [% item.size %]# 1 > > [% hash.size %]# scalar(keys %$hash) > > [% l

Re: [Templates] trueness of arrrays/hashes

2002-01-24 Thread Simon Wilcox
On Fri, 25 Jan 2002, Stas Bekman wrote: > I was wondering why it's always a quiz to figure out whether a value is > empty or not. > [snip example] > so in case of array I must always remember to use: > > IF var.array.size; > > and in case of hash, I don't even remember what was the trick, I t

Re: [Templates] trueness of arrrays/hashes

2002-01-24 Thread Casey West
On Thu, Jan 24, 2002 at 06:11:33PM +, Simon Wilcox wrote: : :Should there be a .empty operator that returns true is empty where empty :means var is either null or undefined ? We already have something that *should* do this. .defined(). Just as in Perl, where defined(@foo) will only return t