Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.0-JSR-6
-
Fix Version/s: 1.8.1, 1.9-beta-1
-
Component/s: None
-
Labels:None
-
Number of attachments :
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.
Patch supporting the definition of a begin() and end() method to be run once at the beginning of the processing of the files, and once at the end after all the processing.