Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

From the split man page

http://perldoc.perl.org/functions/split.html

=====

In time-critical applications, it is worthwhile to avoid splitting into more fields than necessary. Thus, when assigning to a list, if LIMIT is omitted (or zero), then LIMIT is treated as though it were one larger than the number of variables in the list; for the following, LIMIT is implicitly 3:

($login, $passwd) = split(/:/);

=====

and by using the a2p converter,

$ a2p <<< '{ SUM+=$5 } END {printf "%d\n", SUM}'

#!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift; # process any FOO=bar switches

while (<>) { ($Fld1,$Fld2,$Fld3,$Fld4,$Fld5) = split(' ', $_, -1); $SUM += $Fld5; }

printf "%d\n", $SUM;

So this behavior is confirmed.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: