Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
47
Task/Scope-modifiers/AWK/scope-modifiers.awk
Normal file
47
Task/Scope-modifiers/AWK/scope-modifiers.awk
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# syntax: GAWK -f SCOPE_MODIFIERS.AWK
|
||||
BEGIN {
|
||||
# All variables in AWK are considered global
|
||||
a = 1 # global
|
||||
b = 2 # global
|
||||
# c is undefined
|
||||
#
|
||||
x(a) # call function in default namespace
|
||||
printf("a='%s' c='%s'\n\n",a,c)
|
||||
#
|
||||
# A recent addition to GAWK is namespace
|
||||
# The default namespace is "awk"
|
||||
#
|
||||
# All variables in the default namespace may be referenced by
|
||||
# name or awk::name
|
||||
#
|
||||
# All variables in another namespace must be referenced as
|
||||
# namespace::name
|
||||
#
|
||||
# For example to reference function x in the default namespace use
|
||||
# x() or awk::x()
|
||||
#
|
||||
# To reference function x in the "test" namespace use test::x()
|
||||
#
|
||||
# Let's test the two functions named "x" which are shown below
|
||||
#
|
||||
awk::x(22) # call function in default namespace
|
||||
printf("a='%s' c='%s'\n\n",a,c)
|
||||
test::x(22) # call function in another namespace
|
||||
printf("a='%s' c='%s'\n\n",a,c)
|
||||
exit(0)
|
||||
}
|
||||
# Variables are:
|
||||
# - local to functions when specified as arguments
|
||||
# - passed by value except arrays which are passed by reference
|
||||
#
|
||||
function x(a, c) {
|
||||
printf("inside awk::x() a='%s'\n",a)
|
||||
a = c = 9
|
||||
printf("inside awk::x() a='%s'\n",a)
|
||||
}
|
||||
@namespace "test"
|
||||
function x(a, c) {
|
||||
printf("inside test::x() a='%s'\n",a)
|
||||
a = c = 9
|
||||
printf("inside test::x() a='%s'\n",a)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue