Raptorfan wrote:
> From: "Paul Malcher" <[EMAIL PROTECTED]>
>> If you say something like $count = grep(/$condition/,@array1); then
>> $count will a count of how many times the condition occurs. Now if
>> you 
> 
> a minor nit; it would be more correct to use scalar() in that
> case. i'm cleaning up another person's scripts at work and
> one problem is an assumption like the above could (based on
> the calling case) return the first element of the array. if
> the call was
> 
> if ( my $count = scalar(grep(/$condition/,@array ) {   foo;
> }
> 
> .. you are assured $count will always be an integer.
> 
> never ASSume.. or people like me end up cleaning scripts when someone
> turns on strict. :) 

I don't think so, "$count = " provides the scalar context, so "scalar()"
is unnecessary. The documentation for grep clearly says that it returns
a count in a scalar context.

The author of the script you are cleaning up may not have been aware of
ther difference between arays and lists (see 'perldoc -q array'), but
simply wrapping "scalar" around a grep without taking account of the
current context and desired result, is unlikely to help.

HTH

-- 
Brian Raven
 


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary 
companies.
-----------------------------------------------------------------------


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to