Is it possible with GAWK 3.1.6 to create a function witha varaible
number of parametrs?
Thanks all.
Roby
> Hi all.
>
> Is it possible with GAWK 3.1.6 to create a function witha varaible number
> of parametrs?
>
It would help to know what you are trying to do.
AWK doesn't have functions with an unknowable number of parameters, but
all functions are happy if you don't use all the ones you declare (unless
they can't deal with values of zero or null for the unused ones).
--
T.E.D. (tda...@mst.edu)
one way to do is to define a function with more arguments than you
need.
then you print each arg till you hit a nil argument, then stop
for example: http://unbox.org/wisp/trunk/requirez/lib/string/prints.awk
this is used to print long strings without needed to fuss with "\"
characters, see below. note that the "prints" function knows to
a) outout a new line if it sees a string with one character
b) indent with one tab any other line starting with a tab.
function usage() { about(Who,What,When,Why);
prints("Usage: "What" [FLAGS] FILE"," ",
"FILE is columns of data."," ",
" -b NUM width of bars; default=["BarColumnWidth"]",
" -c show copyright",
" -d CHAR field seperator",
" -h show help",
" -k NUM width of 'key' column;default=["KeyColumnWidth"]",
" -m CHAR character to draw one histogram dot; default=["Mark"]",
" -n no sorting of keys",
" -s provides mean and standard deviation of each bar",
" -t NUM target column; default=["Collect"]",
" -v NUM width of 'value' column; default=["ValueColumnWidth"]",
" -w NUM width of each data bin; default=["Round"]");
}
enjoy!
:-)
t
p.s.
this could be a generic tool with the indirect function extension
offered by Robbins in the forthcoming Gawk 3.2 (the function to be
called on the first non-nil arguments could be passed in as arg1)
Depending on the application context I'd probably use one of the three
ways outlined here...
function f(args)
{
for (i=1; i in args; i++)
print "==" args[i] "=="
}
function g(arg)
{
n = split(arg,arr,"|")
for (i=1; i<=n; i++)
print "==" arr[i] "=="
}
BEGIN {
a[++i] = "Hello" ; a[++i] = "world" ; f(a)
b = "Hello|my|good|old|friend" ; g(b)
c = "All|along|the|watchtower" ; split(c,l,"|") ; f(l)
}
Janis
>
> Thanks all.
>
> Roby
>
Beautiful, elegant and complete.
Many thanks.
-re-
Very interesting solution.
Where can I found GAWK 3.2?
Many thanks
-re-
On 2009-04-21, roby <ellero...@katamail.com> wrote:
> [...]
> Where can I found GAWK 3.2?
> [...]
http://tinyurl.com/future-gawk-3-2
- --
Steffen Schuler (goedel) <schuler...@gmail.com>
Key ID: 0x42C5D853 / Key-server: pgp.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAknuIG8ACgkQ+/TWb0LF2FPi5ACfeASbjsgmvMXSLgmD+I7NeMXP
P7MAn3YGD4Q8vO18y2Oe+j+Ts0vyJY3e
=1aJE
-----END PGP SIGNATURE-----
That doesn't look like the kind of tinyurl link I'm used to seeing;
but maybe they've changed how it works?
When I try to use it, though, the tinyurl server never responds. Thus
I wonder if the link is really correct?
I also wondered about that readable link...
>
> When I try to use it, though, the tinyurl server never responds. Thus
> I wonder if the link is really correct?
...but the server responded. The referenced address is
http://cvs.savannah.gnu.org/viewvc/gawk-devel/?root=gawk
Janis
Where can I found the EXE version for Windows XP Professional OS?
Otherwise how can use the source under Cygwin?
Many thanks
Roby
It should be as simple as the usual: ./configure && make
It's been a while since I've done it, but it was just that simple.
Have you tried this yet?