Uploaded image for project: '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
    • 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
    • Flags:
      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.

        Attachments

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

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: