Access to variables outside groovy closure
I'm processing a log file line-by-line in an eachLine closure and need to remember the value from a previous iteration.  The problem is the scope of the "currentCampaign" variable inside the loop is apparently different than outside the loop, so it is not remembered between each iteration. (basically, one line will have the campaign id, then I scan forward for the next instance of a like containing "redirectLink".  I need to remember what the last campaignId was in the file)

<pre>
<code>

    def currentCampaign = ""
    file.eachLine{ line->
        if(line.indexOf("campaignId") != -1){
            currentCampaign = extractCampaign(line)
        }
        if(line.indexOf("redirectlink") != -1){
            recordRedirect(currentCampaign, extractRedirectLink(line))
        }
    }

</code>
</pre>

Access to variables outside groovy closure
===

I'm processing a log file line-by-line in an eachLine closure and need to remember the value from a previous iteration.  The problem is the scope of the "currentCampaign" variable inside the loop is apparently different than outside the loop, so it is not remembered between each iteration. (basically, one line will have the campaign id, then I scan forward for the next instance of a like containing "redirectLink".  I need to remember what the last campaignId was in the file)

<pre>
<code>

    def currentCampaign = ""
    file.eachLine{ line->
        if(line.indexOf("campaignId") != -1){
            currentCampaign = extractCampaign(line)
        }
        if(line.indexOf("redirectlink") != -1){
            recordRedirect(currentCampaign, extractRedirectLink(line))
        }
    }

</code>
</pre>
