In your code, my $c = ("foo" =~ /($a)*$b/)[0]; is an improper use of list slice.
Then enlighten us, what is the "proper use" of list slices to avoid using $1, etc? Note that the OP used the match in an
if statement, so whether the pattern matched or not is important.
If you are saying that "do not use list slice when doing a match global", I would absolutely agree with that. And I do not think that I have recommended that.
Well, you wrote:
In general, I avoid using $1, $5 etc. Use Perl list slice instead.
If you are using words like
in general, followed by an unqualified demand what to use, be prepared for others pointing out cases where the "in general" doesn't work.
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.