in reply to Creating a link in mason
# sample of href from CGI.pm use strict; use diagnostics; use CGI qw(:standard); my $id = CGI::escape(param('id')); print a({-href=>"removecard?card_id=$id"}, "Remove");
Here we loaded the CGI module with standard HTML functions and then assigned the variable $id to the posted variable for the id of the card the person wants to retrieve. (This would be sent to your script by a form or a query string and retrieved through the param() function)
Then we make sure the id will not create a malformed URL by using the CGI::escape() function to convert any characters to their hexadecimal equivalents.
Once this is done we are ready to create the HTML itself. This is done by printing out the return value from the a function, which creates the same HTML as an tag would. The link attributes are sent inside curly braces {} and are defined by the '-href' attribute. The value for the link is enclosed in double quotes ("") so that the $id variable will be interpolated by PERL and create the link to the card.
The last part of the a() function is the text displayed for the link on the page.
A more complete version of this script would need to create the starting and ending HTML and the neccessary header.
For a good general reference on CGI.pm I would suggest the modules manual page at CPAN: http://search.cpan.org/~lds/CGI.pm-3.27/CGI.pm
|
|---|