groovy
  1. groovy
  2. GROOVY-1512

When executing command-line scripts it should be possible to execute a BEGIN and an END method (akin to AWK or Perl)

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Minor 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 :
      2

      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.

      1. GROOVY-1512.patch
        2 kB
        Guillaume Laforge
      2. GroovyMainAll.patch
        3 kB
        Joachim Baumann

        Activity

        Hide
        Guillaume Laforge added a comment -

        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.

        Show
        Guillaume Laforge added a comment - 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.

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Joachim Baumann
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: