Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Adding a variable to a HASH.

Quote Reply
Adding a variable to a HASH.
Hi:

I am NOT God's gift to perl programers- I can barely get by! Hoping someone would help me a bit on this- happy to share the final results if there is any interest.

The project is to allow mutliple detail pages in Links 3.0.I have a plug-in that worked in 2.X, but with some of the changes, well, I have got most worked out, but hit the wall in one regard. I used to just tag the code to point to the "correct" detail page in the URL- just a simple addition of "p=c" in the URL. In 2.0, the Link was pulled in Build.pm, so I just passed the variable to Build, and used that variable to determine the correct template.

In 3.0, page.cgi pulls the link info, thus:

my $link_db = $DB->table('Links');
$link = $link_db->get($id, 'HASH');

and sends that as a hash to Build, thus:

print $IN->header();
print Links::Build::build ('detailed', $link);

I need to add my "p" variable into that hash (I think!) I ahve tried this:

print $IN->header();
print Links::Build::build ('detailed', $link, p => $p);

but that breaks the system and I get errors. Do I use "push (or is it "pull" ?) to add this to the hash? How?

Then, once in Build, I just pull it out with a simple:

$link->{'p'} eq 'c'

right?

I get this, and I should have it all wrapped up!

Thanks!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Adding a variable to a HASH. In reply to
This is the error when I try and add a "&p=c" to the detailed URL:

Invalid argument passed to build_detailed:

Since
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Adding a variable to a HASH. In reply to
You need to dereference the $link hashref, then enclose $link and p inside a new hashref, like so:

Code:
print Links::Build::build ('detailed', { %$link, p => $p});

or you can just add "p" to the $link hashref directly:

Code:
$link->{p} = $p;

and leave the existing build code alone.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Adding a variable to a HASH. In reply to
Thanks!
dave

Big Cartoon DataBase
Big Comic Book DataBase