[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using function arguments
From: |
uzibalqa |
Subject: |
Re: Using function arguments |
Date: |
Fri, 07 Apr 2023 20:59:50 +0000 |
------- Original Message -------
On Thursday, April 6th, 2023 at 9:44 PM, Manuel Collado
<mcollado2011@gmail.com> wrote:
> Please read the gawk manual section on functions.
>
> https://www.gnu.org/software/gawk/manual/gawk.html#User_002ddefined
> https://www.gnu.org/software/gawk/manual/gawk.html#Return-Statement
After reading the links, I am under the impression that function arguments
can only be used as input. For output one can use "result var". I am
struggling about what to do when I want to output a number of variables
set inside the function.
> In short:
>
> function product(a, b) {
> return a * b
> }
>
> HTH.
>
> El 5/4/23 a las 22:41, uzibalqa via Help-gawk escribió:
>
> > I am having difficulties understanding how to use gawk function arguments.
> > Customarily, arguments define variables that are local to the function.
> >
> > But can arguments be used as input that the function can use
> >
> > As example
> >
> > function densel(class, loc) {
> > if (class == 1) { print "Class is 1" }
> > if (class == 2) { print "Class is 2" }
> > loc = 8
> > }
> >
> > BEGIN {
> > class=2
> > densel(class)
> > }
> >
> > Then there is option of using "return class" which can actually return a
> > value by calling
> >
> > x=densel(class)
>
>
> --
> Manuel Collado - http://mcollado.z15.es