Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Use perl CGI to create <a href="url" target="t">text</a>?

by Fletch (Bishop)
on Jun 08, 2022 at 13:29 UTC ( [id://11144517]=note: print w/replies, xml ) Need Help??


in reply to Use perl CGI to create <a href="url" target="t">text</a>?

How do you think CGI generates HTML output if not by printing it? And the documentation itself uses print in several examples (explicitly printing anchors, in fact).

It should take just a second to work out from the _tag_func sub in the code to work out that attributes for tag generation should be passed as a hashref followed by the contents.

$ perl -MCGI -E 'say CGI->new->a( {href => "http://example.com"}, "Sam +ple" )' <a href="http://example.com">Sample</a>

That being said in general it'd be better practice to use a templating engine for your HTML generation with that taking any dynamic values from whatever context its passed. If you look at Mojolicious and the like (Dancer2 (?), edit Dancer2::Template::TemplateToolkit specifically maybe) those use that kind of approach typically.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Use perl CGI to create <a href="url" target="t">text</a>?
by misterperl (Pilgrim) on Jun 08, 2022 at 14:06 UTC
    Thanks, my question wasn't how or if to print. It was about how or if to use $cgi->a() which was answered but TY.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144517]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found