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)

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.8.1, 1.9-beta-1
    • 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.

      Attachments

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

        Activity

          People

            guillaume Guillaume Sauthier
            jbaumann Joachim Baumann
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: