Gossamer Forum
Home : General : Perl Programming :

Oh joy.. hash merging...

Quote Reply
Oh joy.. hash merging...
Hi,

i'm having a really weird problem here :/

Code:
# $IN = { %$IN, %$CFG, %$USER };

require GT::Template;
my $message = GT::Template->parse('add-email-pre.txt',
$IN,
{ compress => 0, root => "$CFG->{admin_root_path}/templates/$CFG->{build_default_tpl}"});

works fine (except it obviously doesn't include $CFG or $USER).

However, if I use;

Code:
$IN = { %$IN, %$CFG, %$USER };

require GT::Template;
my $message = GT::Template->parse('add-email-pre.txt',
$IN,
{ compress => 0, root => "$CFG->{admin_root_path}/templates/$CFG->{build_default_tpl}"});

The error_log shows;

Quote:
[Tue Feb 15 08:51:39 2005] [error] [client 81.153.51.17] Premature end of script headers: /var/home/ultranerds/ultranerds-dev.com/cgi-bin/add.cgi

If I add in print $IN->header();, then it just outputs a blank page (I'm guessing it was trying to output something.... but I can't see where/why :/).

Any ideas are MUCH appreciated. BTW, this is a freebie plugin for LSQL =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
Just a guess, but it seems to me that you are nuking the $IN object by trying to add the contents of the hashes to it.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Oh joy.. hash merging... In reply to
Hi Philip,

Thanks for the reply :)

I thought the same thing. However, I know you can merge hashes with;

$newHash = { %$HASH1, %$HASH2, %$HASH3 };

.. so why won't it do the same with $IN $CFG and $USER? :/

I've tried the following code (without the hash merge), as I know this used to work;

Code:
my $message = GT::Template->parse('add-email-pre.txt',
{ %$CFG, %$USER, %$IN },
{ compress => 0, root => "$CFG->{admin_root_path}/templates/$CFG->{build_default_tpl}"});

But that doesn't work still :/

TIA for any ideas.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
I know have;

Code:
my $newIN = { %$IN, %$CFG, %$USER };
my $message = GT::Template->parse( 'add-email-pre.txt', $newIN, { compress => 0 } );

.. and it doesn't give me a 500 IS error now. However, it still gives me a load of "missing tags". If only we could use Links::SiteHTML::display() with .txt files!!! Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
Anyone? Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
Quote:
my $newIN = { %$IN, %$CFG, %$USER };

$IN is a GT::CGI object, not exactly a hashref. It's been a while since I played with GT::Template but I don't think you can associate objects like you can in HTML::Template. But you should be able to do something like so:

Code:
%$newIN = map { $_ => $IN->param($_)} $IN->param;

In fact, you'd be best off checking the POD for GT::Template to see if you can associate the object somehow. Or if GT::CGI has a method like Vars in CGI.pm. OK, I just checked and it does:

Quote:
get_hash - Return all form input as hash.

This returns the current parameters as a hash. Any values that have the same key will be returned as an array reference of the multiple values.

$CFG is a complex data structure, not a simple hashref. (at least in GMail it is.) You'd have to loop through the keys and flatten out the structure to use it as template args. That a look at the reply by Cees Heck in this post to the HTML::Template mailing list: http://sourceforge.net/...77&forum_id=9830. I think I remember reading that the new version of GT::Template will support flattening.

$USER should work as expected. The GMail $USER is just a simple hashref. Ymmv.

~Charlie
Quote Reply
Re: [Chaz] Oh joy.. hash merging... In reply to
Hi Charlie,

Thanks for the reply Smile

After reading your comments, I finally managed to get this to work;

Code:
my $newIN;
%$newIN = map { $_ => $IN->param($_) } $IN->param;
my $message = GT::Template->parse( 'add-email-pre.txt', { %$newIN, %$USER, %$CFG }, { compress => 0 } );

In LSQL, you can reference $CFG and $USER as a simple hashref. i.e $USER->{Username} and %$CFG->{build_root_url} ... I'm not so sure about other GT products ...but it seems to work in LSQL <G>

Thanks again.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
Hi Andy,

Try this too:

Code:
my $message = GT::Template->parse( 'add-email-pre.txt', { $IN, %$USER, %$CFG }, { compress => 0 } );

And see if GT::Template likes the $IN object. I just looked over get_tags in GMail.pm and it looks like they just push (unshift actually) the object right in there. I'd be interested to see if it works.

OK, just checked GT::Template and it should work:

Code:
elsif (ref $p eq 'GT::CGI' or ref $p eq 'CGI') {
for ($p->param) {
$self->{VARS}->{$_} = $p->param($_);
delete $self->{DELAY_VARS}->{$_};
}
}

That's with version 2.111.

~Charlie
Quote Reply
Re: [Chaz] Oh joy.. hash merging... In reply to
Hi,

my $message = GT::Template->parse( 'add-email-pre.txt', { $IN, %$USER, %$CFG }, { compress => 0 } );

Doesn't work :(

Normally, just using;

{ %$IN, %$CFG, %$USER }

works fine... maybe its a 2.1.2 to 2.2.x change :/

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
Bummer :/ Maybe someone from GT can shed some light on it. It must be something to do with the version of GT::Template.

Anyhow, the get_hash method might still save yo ua few keystrokes:

Code:
{ $IN->get_hash, %$CFG, %$USER }

~Charlie
Quote Reply
Re: [Chaz] Oh joy.. hash merging... In reply to
Mmm.. back to stage one :(

$message = GT::Template->parse('ppc_user_paypal_success_email.txt',
{ $IN->get_hash, %$CFG, %$USER },
{ compress => 0, root => "$CFG->{admin_root_path}/templates/$CFG->{build_default_tpl}"});

$subject = "Your PayPal Payment has been successful ($custom)";


... gives undef for all the options. ARGH!!!!!!

There *has* to be something going on with GT::Template->parse() ????

Unimpressed

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Oh joy.. hash merging... In reply to
Managed to get it working with this;

Code:
my $NEWHASH = $IN->get_hash;

my $newIN;
map { $newIN->{$_} = $IN->param($_)} keys %$NEWHASH;
map { $newIN->{$_} = $CFG->{$_}} keys %$CFG;
map { $newIN->{$_} = $bid_rec->{$_}} keys %$bid_rec;

There must be an easier way though :(

GT?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!