|
From: | Jaromir Obr |
Subject: | Re: [bug-gawk] Missing double quotes in SYMTAB example in docs |
Date: | Mon, 11 Jul 2016 21:49:33 +0200 |
Hi.
What you want is
multiply("i", 2)
Note that the `i' in the multiply function is different from the
global `i' assigned to in the BEGIN rule.
HTH,
Arnold
Jaromir Obr <address@hidden> wrote:
> Based on the example originally I tested this:
>
> BEGIN {
> i = 10
> multiply(i, 2)
> print i
> }
> function multiply(i, amount)
> {
> return SYMTAB[i] *= amount
> }
>
> but it didn't work as expected (result is 10 instead 20). Therefore I would
> expect SYMTAB["i"].
>
> Mira
>
> On Sun, Jul 10, 2016 at 10:25 PM, david kerns <address@hidden>
> wrote:
>
> > if it used less descriptive names, say a and b, would you still say it
> > needs double quotes?
> >
> > # Indirect multiply of any variable by amount, return result
> >
> > function multiply(a, b)
> > {
> > return SYMTAB[a] *= b
> > }
> >
> >
> > On Sun, Jul 10, 2016 at 10:24 AM, Jaromir Obr <address@hidden>
> > wrote:
> >
> >> Hi,
> >>
> >> in
> >> https://www.gnu.org/software/gawk/manual/gawk.html#index-differences-in-awk-and-gawk_002c-SYMTAB-variable
> >> there is an example:
> >>
> >> # Indirect multiply of any variable by amount, return result
> >>
> >> function multiply(variable, amount)
> >> {
> >> return SYMTAB[variable] *= amount
> >> }
> >>
> >>
> >> There are missing double quotes around variable, aren't they ? (expected
> >> is return SYMTAB["variable"] *= amount
> >>
> >> Regards
> >>
> >> Jaromir
> >>
> >
> >
[Prev in Thread] | Current Thread | [Next in Thread] |