manpagez: man pages & more
info gawk
Home | html | info | man

File: gawk.info,  Node: Global Namespace,  Next: Qualified Names,  Up: Namespaces

15.1 Standard 'awk''s Single Namespace
======================================

In standard 'awk', there is a single, global, "namespace".  This means
that _all_ function names and global variable names must be unique.  For
example, two different 'awk' source files cannot both define a function
named 'min()', or define the same identifier, used as a scalar in one
and as an array in the other.

   This situation is okay when programs are small, say a few hundred
lines, or even a few thousand, but it prevents the development of
reusable libraries of 'awk' functions, and can inadvertently cause
independently-developed library files to accidentally step on each
other's "private" global variables (*note Library Names::).

   Most other programming languages solve this issue by providing some
kind of namespace control: a way to say "this function is in namespace
XXX, and that function is in namespace YYY."  (Of course, there is then
still a single namespace for the namespaces, but the hope is that there
are much fewer namespaces in use by any given program, and thus much
less chance for collisions.)  These facilities are sometimes referred to
as "packages" or "modules".

   Starting with version 5.0, 'gawk' provides a simple mechanism to put
functions and global variables into separate namespaces.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.