[PLUG] Adding numbers
Felix Lee
felix.1 at canids.net
Thu Jan 29 03:47:01 UTC 2004
Russell Senior <seniorr at aracnet.com>:
> That'll work, but the BEGIN clause is superfluous. Variables default
> to zero anyway, so it can reduce to:
> $ awk '/missing/ { total += $7 } END { print total }' messages*
no, variables default to null. if no lines match, then your
version prints a blank line instead of 0. another way of getting
0 is to say
END { print total + 0 }
but I think that's conceptually weirder than using BEGIN to set
the initial value to 0. initialization is a simple idea, it
transfers to any language.
--
More information about the PLUG
mailing list