in reply to There are a million ways to quote. How can you determine the best/safest?
My (personal and improvised) formula is:
-> yes: " double $quote "
-> no: ' single quote '
-> yes: use the according quote-like-operators (q or qq) with convenient q!delimiter!.
-> yes: use <<heredocs (i.e. multi-char-delimiter) or the <DATA>-section
-> yes: use files or a DB and/or a template system
qw is a special case of q which automatically splits on whitespaces.
Regexes and system-calls are different beasts, but rules are similar, cause they operate on interpreted strings as input. (NB s/// and m// allow other delimiters, too!)
quotemeta is very good if you can't control an "injected" string in an "interpreted" context like in a regex or with string-eval
As you can see it's mainly a compromise between readability, maintainability and avoiding delimiter-problems.
YMMV, readability is often a matter of taste.
It also depends on number of collaborators, performance, scalability, the expected future of the project, and so on...
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: There are a million ways to quote. How can you determine the best/safest?
by taint (Chaplain) on Nov 16, 2013 at 21:32 UTC |