in reply to Re: Scalar Vs. List context
in thread Scalar Vs. List context
and 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
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...$_ = "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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Scalar Vs. List context
by jrsimmon (Hermit) on Jul 11, 2009 at 18:53 UTC |