Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Passing Arguments to a Global Sub

Quote Reply
Passing Arguments to a Global Sub
I'm trying to craft a global sub that will accept multiple arguments and use them to return an HTML string that's embedded in the page.

Essentially, the global spits out some HTML to build a table around a section of the template, and I want to be able to pass the width and height of the table to the sub. Something like this:

# global begin_table
sub {
my ($width, $height) = shift;
my $output = "";
my $output = "<table width=$width>";
my $output .= "<tr><td height=$height>";
return $output;

Assuming it would be called from a template like:


But when I've done it like this, I get a value for $width, but $height is always undef.

Looking through the examples, it looks like the initial argument will always be a hashref to tags that are available (e.g., $vars = shift;), but if that's the case, why am I getting a value for $width...particularly one that looks reasonable??

What am I missing here??

Eric Longman
Quote Reply
Re: [WebWiz] Passing Arguments to a Global Sub In reply to
That should work. Otherwise, try this;

my $width = $_[0];
my $height = $_[1];


my ($width, $height) = @_;


Andy (mod)
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] Passing Arguments to a Global Sub In reply to
Thanks, Andy.

I switched it to use

my ($width,$height) = @_;

and that did the trick. Duh. I should have figured that out!

Eric Longman