SPUG:Best One-Liners and Scripts for UNIX

Yitzchak Scott-Thoennes sthoenna at efn.org
Sun Apr 27 00:49:17 CDT 2003


On Sat, 19 Apr 2003 10:37:13 -0700, tim at consultix-inc.com wrote:
>        ($fields = shift) =~ /^[\d,.]+$/g or

That trips a warning if the script is given no args.  Make it:
$fields = shift and $fields =~ ... 

>	@fields = eval " ( $fields ) ";	# 5,2..4 => 5,2,3,4

The parens there aren't necessary.  You need parens for something
like: @fields = (5,2..4) just for correct precedence ('=' is lower
precedence than ','), but with the eval there, there is no precedence
problem.  Parens almost never affect anything besides precedence.
(Two major exceptions are around the left operands of '=' and 'x':
there the behaviour of the operator completely changes.  I thought
there was a third important exception but can't remember what it was.)



More information about the spug-list mailing list