...

View Full Version : Create custom link tag using Perl CGI



djperrier
10-29-2009, 07:18 PM
In a nutshell, I want know if there is a way to do this using the CGI module or submodules:

Given a href script path (relative to server) and a CGI object with parameters (a, b, c) output a proper tag, such as:

<a href="some_cgi_script.pl?a=value1&b=value2&c=value3">some text</a>

Could I use the link method ( CGI->a() ) for this?

I would imagine there is some way to create the tag with a query string attached...

Now I KNOW I could just get the query string string and append:

CGI->a( $url . '?' . $query_string, 'some_text' );

...for example, but I am looking for a more elegant solution...


Thanks,
-Nathan

oesxyl
10-29-2009, 10:23 PM
In a nutshell, I want know if there is a way to do this using the CGI module or submodules:

Given a href script path (relative to server) and a CGI object with parameters (a, b, c) output a proper tag, such as:

<a href="some_cgi_script.pl?a=value1&b=value2&c=value3">some text</a>

Could I use the link method ( CGI->a() ) for this?

I would imagine there is some way to create the tag with a query string attached...

Now I KNOW I could just get the query string string and append:

CGI->a( $url . '?' . $query_string, 'some_text' );

...for example, but I am looking for a more elegant solution...


Thanks,
-Nathan
define elegant, :) This is a matter of imagination, in my opinion, you can design your code as you like.

I'm curios if this is elegant?:


my %link = ('a' => 'a_value',
'b' => 'b_value',
'c' => 'c_value');
my $base = 'some_cgi_script.pl';

my $url = $base . '?' . join '&' map { $_."=".$link{$_}; } keys %links;


I didn't test it, I guess it work, but I'm not so sure that is a elegant solution, maybe a complex one. I would avoid a complex solution to something if I have one simple.

best regards

djperrier
10-29-2009, 10:26 PM
define elegant, :) This is a matter of imagination, in my opinion, you can design your code as you like.

I'm curios if this is elegant?:


my %link = ('a' => 'a_value',
'b' => 'b_value',
'c' => 'c_value');
my $base = 'some_cgi_script.pl';

my $url = $base . '?' . join '&' map { $_."=".$link{$_}; } keys %links;


I didn't test it, I guess it work, but I'm not so sure that is a elegant solution, maybe a complex one. I would avoid a complex solution to something if I have one simple.

best regards

That's my point. I would imagine that this is a problem run into often enough that would warrent a built-in CGI function rather than simply appending a '?' between a url and a query string!

oesxyl
10-29-2009, 10:37 PM
That's my point. I would imagine that this is a problem run into often enough that would warrent a built-in CGI function rather than simply appending a '?' between a url and a query string!
that's the key question, :) If this is the case I would write a sub, probably I would detect some pattern and write the code in a way that make my life easy, :)
For exmaple you could do some checking, undef or missing arguments, use a callback for validation, and so on, :)
As I said is a mater of imagination, :)

best regards

djperrier
10-29-2009, 10:47 PM
I know. I'm asking if there is something in a standard module (such as CGI.pm, for instance) that already does this.

oesxyl
10-29-2009, 10:57 PM
I know. I'm asking if there is something in a standard module (such as CGI.pm, for instance) that already does this.
I don't know to be and I don't know if there is a module to do that. One place where you could search for ideas is inside some frameworks like Catalyst or others.
Maybe FishMonger or others on this forum can help.

best regards

FishMonger
10-30-2009, 12:37 AM
Your question is a little vague.

Where is the data coming from for the query string?

What is so inelegant with the $cgi->() method?

Exactly what do you want the, yet unknown elegant, method to do that the $cgi->() method doesn't do?

Can you provide some pseudo code of the process that you want to accomplish?



map { $_."=".$link{$_}; }
is better written as:

map { "$_=$link{$_}" }

lokamesa
11-22-2009, 01:39 AM
define elegant, :) This is a matter of imagination, in my opinion, you can design your code as you like.

I'm curios if this is elegant?:


my %link = ('a' => 'a_value',
'b' => 'b_value',
'c' => 'c_value');
my $base = 'some_cgi_script.pl';

my $url = $base . '?' . join '&' map { $_."=".$link{$_}; } keys %links;



Thanks for sharing!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum