diff options
| author | Abigail <abigail@abigail.be> | 2021-01-15 19:49:13 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-15 20:14:41 +0100 |
| commit | 9251a29076c9db7d43369aa4b3eb4c7bf55dc134 (patch) | |
| tree | 2b8b459795e3037b575a0015232820c64ce82264 /challenge-095/abigail/awk | |
| parent | a2cf8e3faa0fbfcc4fdc66bcaafae5b659ef4fc5 (diff) | |
| download | perlweeklychallenge-club-9251a29076c9db7d43369aa4b3eb4c7bf55dc134.tar.gz perlweeklychallenge-club-9251a29076c9db7d43369aa4b3eb4c7bf55dc134.tar.bz2 perlweeklychallenge-club-9251a29076c9db7d43369aa4b3eb4c7bf55dc134.zip | |
Use 'delete' to remove elements from the array.
Diffstat (limited to 'challenge-095/abigail/awk')
| -rw-r--r-- | challenge-095/abigail/awk/ch-2.awk | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/challenge-095/abigail/awk/ch-2.awk b/challenge-095/abigail/awk/ch-2.awk index d407cc7e74..b88c1e87f0 100644 --- a/challenge-095/abigail/awk/ch-2.awk +++ b/challenge-095/abigail/awk/ch-2.awk @@ -1,8 +1,11 @@ BEGIN { - size = 0 error = "Stack is empty" } +{ + size = length (stack) +} + /^push/ { # # Push the argument on the stack. We use split to retrieve @@ -10,15 +13,14 @@ BEGIN { # second argument -- an array. Note that arrays are indexed 1-based. # split($0, a, / +/) - stack [size += 1] = a [2] + stack [size + 1] = a [2] } /^pop/ { # - # Popping just means reducing the size of the stack by 1. - # Don't let it go below 0. + # Remove the last element from the stack. # - size = size ? size - 1 : 0 + delete stack [size] } /^top/ { |
