What has been particularly confusing is that in the literature I have gone through-so far-there is nothing that clearly addresses this distinction and the "usage outcomes" of these contexts with supporting examples in a central manner like a chapter or topic , I thought it was not serious in the start until I have landed at the regexes and that is when I am fully aware I need to understand this before missing the chance.. and for the benefit of everyone who is caught in a similar fix I thought I am obliged to talk this out with the Monks and seek their wisdom therefore, consider this
$text="Tommy tom ticked a tick at the ticket counter";
$t_count=($text=~ y/[tT]/t/);
print "This text has $t_count Ts\n";
#result
#This text has 9 Ts
and this
$_ = "1.0 and 2.4 and 310 and 4.7 and so on";
@a = m/([\d|\.]+)\D+/g;
print "@a\n";
#result
#1.0 2.4 310 4.7
so we used the =~ in the first example and the only = in the second example (matching is used here with list context, but I would know it only after having run the code not while reading the code), this might be very plain to see for the expert but not for me. Hence I want to know the parameters for using scalar and list contexts, the differences between these contexts and the common pitfalls the novice would come across with regard to this.
So what I seek is a short sharp to the point explanation of what list context usage WOULD return and what scalar context usage WOULD return for some of the operations and techniques in Perl...
Excellence is an Endeavor of Persistence.
Chance Favors a Prepared Mind
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.