SPUG: Grep syntax
Bill Campbell
bill at celestial.com
Thu Jun 14 23:39:46 PDT 2007
Speaking of documentation, or lack thereof.
I just ran across a snippet of perl that I don't undertand at
all. In this, the array @a contains octets of an IP address, and
it appears that the authoer wanted to set $start0. As nears as I
can tell after trying various contents of @a, $start0 is changed
to 0 if there are *ANY* non-zero elements of the array @a.
$start0=1;
grep { $start0=0 unless $_ == 0; } @a;
if ( ! $start0 ) { ...
It appears to me that this is a rather cryptic way of checking
that the array is empty or contains only 0 elements, and that the
grep command could be replaced with map or a simple loop.
Bill
--
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
http://www.celestial.com/
"I do not feel obliged to believe that the same God who has endowed us
with sense, reason, and intellect has intended us to forego their use."
-- Galileo Galilei
More information about the spug-list
mailing list