Keep It Simple, Stupid | |
PerlMonks |
Re^3: Joining an arrayby tobyink (Canon) |
on Feb 11, 2012 at 09:02 UTC ( [id://953189]=note: print w/replies, xml ) | Need Help?? |
Generally speaking I prefer sprintf over interpolation ("$foo=$bar") except in very trivial cases. When you need to put $foo and $bar into a string, interpolation is fine. But if you need to put $foo->[1]{name} and encode_entities($bar->get_url("print")) into a string, sprintf looks much better:
Bear in mind that if you're outputting this URL in HTML, there are two types of escaping you need; and you need to do them both at the appropriate stage.
That is, URI escaping (which deals with things like space being encoded as %20) needs to be done to each component of the URI, but not the URI as a whole. And HTML entity encoding (which deals with things like "&" becoming "&") needs to be done to all strings used in the HTML. That assumes you're building your HTML using string processing, which is what many people do. If you're instead building it using a DOM library (e.g. XML::LibXML, HTML::HTML5::Builder, etc) then the library should take care of the HTML entity encoding, but it won't attempt URI escaping.
In Section
Seekers of Perl Wisdom
|
|