On 9/10/06, chen li <[EMAIL PROTECTED]> wrote:

So map function returns the transformed or changed
elements but not the original ones and grep still
returns the original ones?

The only thing grep can return are the elements of the original list,
but it generally doesn't return all of them.

For example after certain
operation  A changes to B, in case of map the return
is B but in case grep the return  is still A. Is that
right?

What do you mean by "A changes to B"? It sounds as if you're talking
about a map expression that takes A (in $_) as input and returns B
(the value of the map expression). In that case, B is a list
expression, so it may include any number of elements, even zero. But
from what you've written, I think you're thinking of the case where B
is a single value. That is to say, your map expression turns one input
value into one output value.

If you were to use that same expression in grep, it would be evaluated
in scalar context. The scalar context value of an expression may be
unrelated to the value than it would give in list context. In grep,
it's a Boolean context, which is a special kind of scalar context. If
the grep expression returns a true value, the original element is
included; otherwise it's not.

Cheers!

--Tom Phoenix

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to