Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.0-JSR-6
-
None
-
None
-
Patch
Description
When executing a command-line script e.g., via -pe it would sometimes be very useful to define a method BEGIN and a method END which are executed exactly once, BEGIN before the loop starts, and END after the loop has ended for all files to be processed. An example:
groovy -a -ne "def BEGIN()
{c=0};def END()
{println c};c += split[0].toInteger()+split[-2].toInteger()" test.txt
results in:
39
for the following test.txt:
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
The patch provides this functionality and additionally that of GROOVY-1507 and GROOVY-1508. If a singular patch is necessary, I'll be happy to provide it.