Re: template toolkit .. one more kwestion solved

2001-01-29 Thread Paul Makepeace

On Mon, Jan 29, 2001 at 05:31:52PM +0100, Philip Newton wrote:
> Reminds me of fits I had when doing Vignette/Tcl with lists of lists that I
> passed to another template with HTTP POST. When the list of lists contained
> only one element, it didn't wrap that list in extra {} so the foreach say a
> list of lists all right -- but the "sublists" were only one element long
> (since {} are optional around lists if there are not spaces). Caused me a

Try creating a JavaScript array of length one whose first
element is initialised to 1.  Aaargh. [1]

Paul


[1]

# These numbers get turned into a JavaScript array later on that
# looks like new Array (1,1,0); Owing to JavaScript1.0 braindeadedness
# new Array (1) is interpreted as "created a one element list" not
# "create a one element list with [0]=1". However this is achievable
# if the number is given as a string like new Array("1");

@time_names = sort {$a <=> $b} keys %time_names;
foreach my $i_list (keys %time_cache) {
$time_cache{$i_list} =
join ',', map {$time_cache{$i_list}{$_} ? 1 : 0} @time_names;
$time_cache{$i_list} =~ s/^(.)$/"$1"/;
}




Re: template toolkit .. one more kwestion solved

2001-01-29 Thread Philip Newton

Robin Szemeti wrote:
> It seem T::T automagically assumes that if you pass it a reference to
> something then you probably didn;t want that, you prolly 
> wanted the thingy itself so it dereferences it for you.. it will
> only do this down one level.
> 
> so by passing it a list of references it sees a list .. does a foreach
> down them and then sees what it gets (in this case an array 
> ref ) .. it dereferences that and bingo you can now access the row
> of stuff.
> 
> however when the list jsut contains 1 item, it sees a reference to an
> array ( whicj is the row) and then proceeds to do a foreach over the
> elements of the row ..

Reminds me of fits I had when doing Vignette/Tcl with lists of lists that I
passed to another template with HTTP POST. When the list of lists contained
only one element, it didn't wrap that list in extra {} so the foreach say a
list of lists all right -- but the "sublists" were only one element long
(since {} are optional around lists if there are not spaces). Caused me a
bit of a headache, too. I finally settled on looking at the llength of the
first element, and if it's only one, assuming that the big list only had one
element (if the llength was 5, then I was fine, since the sublists were
supposed to have five element).

Cheers,
Philip
-- 
Philip Newton <[EMAIL PROTECTED]>
All opinions are my own, not my employer's.
If you're not part of the solution, you're part of the precipitate.



Re: template toolkit .. one more kwestion solved

2001-01-29 Thread Robin Szemeti

On Mon, 29 Jan 2001, you wrote:

> > Sounds like your dereferencing function may be returning a SCALAR instead
> > of an ARRAY when there's only one result?
> 
> could be ... I had :
> 
> my($data)=$sth->fetchall_arrayref;
> return @{$data};
> 
> which I thought should return a flat list of references to arrays ... ??
> nope?

so .. after a quick fiddle .. 

It seem T::T automagically assumes that if you pass it a reference to
something then you probably didn;t want that, you prolly wanted the thingy
itself so it dereferences it for you.. it will only do this down one
level.

so by passing it a list of references it sees a list .. does a foreach
down them and then sees what it gets (in this case an array ref ) .. it
dereferences that and bingo you can now access the row of stuff.

however when the list jsut contains 1 item, it sees a reference to an
array ( whicj is the row) and then proceeds to do a foreach over the
elements of the row ..

by simply not passing it the thing in list format  but passing the plain
reference (ie return $data instead of @{$data}) it always gets an arrayref
and works for both cases of 1 or n items in the array.

solved .. it just took me a while to twig what was going on.

-- 
Robin Szemeti

The box said "requires windows 95 or better"
So I installed Linux!



Re: template toolkit .. one more kwestion

2001-01-29 Thread Robin Szemeti

On Mon, 29 Jan 2001, you wrote:
> In message <[EMAIL PROTECTED]>,
> Robin Szemeti <[EMAIL PROTECTED]> writes:
> > this works fine if the function returns a list with more than one thing
> > in it .. if there is only one thing in the array I get a 'dont know how
> > to access [ 3 ].0  if for example item 3 is returned.
> > 
> > if I access the result as just plain [% item %] it works fine if there is
> > one item in the list .. and returns lots of ARRAY0x1241234 if there is
> > more than one ...
> 
> Sounds like your dereferencing function may be returning a SCALAR instead
> of an ARRAY when there's only one result?

could be ... I had :

my($data)=$sth->fetchall_arrayref;
return @{$data};

which I thought should return a flat list of references to arrays ... ??
nope?

-- 
Robin Szemeti

The box said "requires windows 95 or better"
So I installed Linux!



Re: template toolkit .. one more kwestion

2001-01-29 Thread Rob Partington

In message <[EMAIL PROTECTED]>,
Robin Szemeti <[EMAIL PROTECTED]> writes:
> this works fine if the function returns a list with more than one thing
> in it .. if there is only one thing in the array I get a 'dont know how
> to access [ 3 ].0  if for example item 3 is returned.
> 
> if I access the result as just plain [% item %] it works fine if there is
> one item in the list .. and returns lots of ARRAY0x1241234 if there is
> more than one ...

Sounds like your dereferencing function may be returning a SCALAR instead
of an ARRAY when there's only one result?
-- 
rob partington % [EMAIL PROTECTED] % http://lynx.browser.org/