[ic] [query] hashref into scratches... this should work me thinks

Paul Jordan paul at gishnetwork.com
Fri Dec 3 06:19:19 UTC 2010




> Date: Fri, 3 Dec 2010 18:27:42 +1300
> From: peter at pajamian.dhs.org
> To: interchange-users at icdevgroup.org
> Subject: Re: [ic] [query] hashref into scratches... this should work me thinks
> 
> On 03/12/10 11:45, Paul Jordan wrote:
> > 
> > I am not perl guru, but from what I read in the docs and archives, I
> > believe this should work but I'm not getting any joy.
> > 
> > [query table=mytable ml=1 hashref=foo sql=|
> > SELECT bin, bat, baz
> > FROM mytable
> > WHERE code = 1001
> > | /]
> > [calc]
> > my %bar = $Tmp->{foo};
> > while (my ($k,$v) = each %bar) { $Tag->tmp($k, $v) }
> > [/calc]
> > 
> > results ====<br />
> > Bin: [scratch bin]<br />
> > Bat: [scratch bat]<br />
> > Baz: [scratch baz]
> 
> [perl mytable]
> my $db = $Db{mytable};
> @{$Scratch}{qw{bin bat baz}} = $db->get_slice(1001, [qw{bin bat baz}]);
> return;
> [/perl]

 
Thanks Peter, that's pretty handy/cool. Actually, my email was simplified for brevity - I am doing more complex joins. I was working on Gerts suggestion, but I was getting:
 
...Safe: Not a HASH reference at (tag 'perl') line 3.
>   my $bar = $Tmp->{foo};
>   while (my ($k,$v) = each %$bar) { $Tag->tmp($k, $v); };
 
So I have been playing with mutations of that, googling things, but in the end I'm 50% guessing 50% learning :-) I think I got this to work though:
 
        [perl]
            my $bar = $Tmp->{foo};
            foreach my $row (@$bar) {
                while (my ($k,$v) = each(%$row)) { $Tag->tmp($k, $v); }
            }
        [/perl]

But that is literally [tmp] right? So i'll need to do something like ..$Scratch->{$k} = $v;
 
With something like this, I feel comfortable enough to just write the query itself in perl too.
 
Thanks guys
 
Paul
 
 
 
  		 	   		  


More information about the interchange-users mailing list