Creating an Array: Difference between revisions

Content added Content deleted
No edit summary
m (→‎{{header|AWK}}: merging from array init)
Line 112: Line 112:


=={{header|AWK}}==
=={{header|AWK}}==
"Numeric" arrays coincide with hashes in awk. Indices begin at 1.
"Numeric" arrays coincide with hashes in awk. Indices begin at 1. The <tt>split</tt> function can be used to initialize an array from a string with elements separated by a field separator (space by default)
<lang awk>BEGIN {
<lang awk>$ awk 'BEGIN{split("this and that",a);for(i in a)print i":"a[i]}'
split("this and that",a)
1:this
for(i in a) print i":"a[i];
2:and
3:that</lang>
}</lang>
Otherwise we can initialize an array by assigning to single elements:
<lang awk>capital["France"]="Paris"
capital["Italy"]="Rome"</lang>


=={{header|BASIC}}==
=={{header|BASIC}}==