In the spirit of "what's old is new again," PowerShell also has the same idea, and is done per Function with "begin", "process", "end", and "clean" stanzas that allow setup, teardown, for-each-item, and "finally" behavior: https://learn.microsoft.com/en-us/powershell/module/microsof...
Oh, that’s an interesting take. I’ve long been looking for newer developments on Awk’s clause structure, and this seems like an interesting take (though I’m unclear on whether I can have multiple begin/end clauses, which are the best thing about Awk’s version). It also finally connects this idea to something else in my mind—specifically advice[1] and CLOS’s :before/:after/:around methods[2]. (I guess Go’s defer also counts?)
function Fred {
begin {
echo "hello from begin1"
}
begin {
echo "hello from begin2"
}
process {
echo "does the magic"
}
}
$bob = @("alpha" "beta")
$bob | Fred
Then
$ pwsh fred.ps1
ParserError: /Users/mdaniel/fred.ps1:5
Line |
5 | begin {
| ~~~~~~~
| Script command clause 'begin' has already been defined.
In the spirit of "what's old is new again," PowerShell also has the same idea, and is done per Function with "begin", "process", "end", and "clean" stanzas that allow setup, teardown, for-each-item, and "finally" behavior: https://learn.microsoft.com/en-us/powershell/module/microsof...