Perl Tip 3: Alternative quote characters; get rid of the mess
[email protected] (Ask Bjoern Hansen) Thu, 26 Jul 2001 13:50:30 -0700 (PDT)
| Newsgroups | perl.tips |
|---|---|
| Message-ID | <[email protected]> |
We are at the Perl Conference in San Diego having lots of fun and
learning lots of cool new stuff. Be sure to follow the coverage at
http://use.perl.org/ and http://www.perl.com/ :-)
On to the tip: Anyone have seen code like
print "<a href=\"http://$url/\">$site</a> (\"$title\")";
Now, it is quite annoying to read all those \'s, so you would think
there is a better way.
Well, there is! :-)
The above line could be written as
print qq[<a href="http://$url/">$site</a> ("$title")];
So instead of using " as the quote operator we used qq[ and ] to end
the quote.
You can also use for example qq{ (or any other form of "brackets"), like
print qq{...};
Like "text" can be substituted with qq[text] you can use a single q
for ', so a confusing statement like
'\'[email protected]\''
can be written as
q['[email protected]']
instead.
For more information, run "perldoc perlop" and search for "Quote and
Quote-like Operators".
To unsubscribe: mail [email protected]
To subscribe: mail [email protected]
Or visit: http://learn.perl.org/tips/
Comments, suggestions? Send them to [email protected].