On Jan 3, Matthew Lyon said:

>On Thu, 3 Jan 2002, Jeff 'japhy' Pinyan wrote:
>
>> I'd use grep():
>> 
>>   @compressed = grep length, @array;
>> 
>> That only allows elements with a non-zero length to get through.
>
>wait! how does this grep trickery work? where's the circuitry?

Uh... it's what grep() does.  My code is the same as the slightly more
verbose:

  @compressed = grep { length($_) != 0 } @array;

which means "all those elements whose length is not zero."  First, I left
out the argument to length(), which assumes $_ if no argument is given.
Second, I used the return value of length() as a true-false value -- if
length() returns some that's not zero, that value is true.  Third, I often
use the grep(EXPR, LIST) format, instead of grep(BLOCK LIST).

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to