new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
30
Task/Arrays/AWK/arrays.awk
Normal file
30
Task/Arrays/AWK/arrays.awk
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
BEGIN {
|
||||
# to make an array, assign elements to it
|
||||
array[1] = "first"
|
||||
array[2] = "second"
|
||||
array[3] = "third"
|
||||
alen = 3 # want the length? store in separate variable
|
||||
|
||||
# or split a string
|
||||
plen = split("2 3 5 7 11 13 17 19 23 29", primes)
|
||||
clen = split("Ottawa;Washington DC;Mexico City", cities, ";")
|
||||
|
||||
# retrieve an element
|
||||
print "The 6th prime number is " primes[6]
|
||||
|
||||
# push an element
|
||||
cities[clen += 1] = "New York"
|
||||
|
||||
dump("An array", array, alen)
|
||||
dump("Some primes", primes, plen)
|
||||
dump("A list of cities", cities, clen)
|
||||
}
|
||||
|
||||
function dump(what, array, len, i) {
|
||||
print what;
|
||||
|
||||
# iterate an array in order
|
||||
for (i = 1; i <= len; i++) {
|
||||
print " " i ": " array[i]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue