Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI - Perl variable inside a HREF

Status
Not open for further replies.

r4k

Technical User
Dec 30, 2006
2
0
0
GB
Hello there,

I wonder if anyone can tell me if its possible to have a variable inside a href html link. In other words could i dynamically generate a series of html links by iterating thru an array. For example, like in this perl cgi extract....

for ($i = 1; $i <= 10; $i++) {
value=array;
<A href="prog1.cgi?data=${value}">$value</A>
}

so i am using a different querystring value in the link each interation of the loop. If this is not possible I would appreciate if anyone could suggest something else.

Many thanks in advance ...... :)

r4k

 
I think what you are looking for is along the lines of an associative array. I have written an example of use below.
Code:
#!/usr/bin/perl

use strict;

my %links = (
    'Google' => 'google.com',
    'Perl'   => 'perl.org',
    'W3C'    => 'w3c.com',
);

print "content-type: text/html\n\n";

while ( my ( $site, $url ) = each(%links) ) {
    print qq{
        <a href="[URL unfurl="true"]http://$url">$site</a>[/URL]
    };
}

M. Brooks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top