No doubt, this works. But it's doing a lot of work it doesn't need to.
- Copying the whole string around. You're matching the whole string, except for the terminating comma, and then copying it back into $query1.
- And then you're going to search the string again, presumably in case there is a second ending comma.
- And what is the 's' for? You may have a habit of using it, thinking it solves a lot of your problems. I think you might be cultivating a bad habit - perl probably does things as defaults that are good things, and you want to specify overriding behaviour only when you need it. (Minimalist theory.)
For the first one, just get rid of the (.*) and $1: $query1 =~ s#,$##gs. For the second, just add an appropriate plus sign: $query =~ s#,+$##s. For the last, well, just remove the ending s - it's not doing anything: $query =~ s#,+$##.
"Premature optimisation is the root of all evil." Well, I'm not optimising - I'm merely encouraging idiomatic use of perl: writing perl the way it should be. Minimally, but not unreadably. (The last part doesn't apply to obfu's and golf competitions.)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.