I'm trying to parse a 2-dimensional array and I'm getting the message "fatal: asorti: first argument not an array;" on the line "n2 = asorti(ss[sub1],sortedSS2);".
ss is the original 2-dimensional array. Not sure why it thinks that ss[sub1] is not an array.
Appreciate in advance the effort to show me what I'm missing.
I'm trying to parse a 2-dimensional array and I'm getting the message "fatal: asorti: first argument not an array;" on the line "n2 = asorti(ss[sub1],sortedSS2);".
ss is the original 2-dimensional array. Not sure why it thinks that ss[sub1] is not an array.
Appreciate in advance the effort to show me what I'm missing.
Steve
===
The script followings:
# Create task list
#
function getValue(num,title) {
getline;
if (length($0)) {
ss[num, title] = $0;
# print "ss[" num "," title "]= " $0
}
return
}
BEGIN {
PROCINFO["sorted_in"]="@ind_str_asc";
titleList = "Number;Submitted by;Created by;Location;Affected End-user;Affected User Building Number;Affected User Room Number;Telework;Best Contact Method;Affected User Best Fol low-up Phone Number;Category;Subcategory;Created by;Portfolio;Product Line;Affected Service;Affected CI;Contact type;State;On hold reason;Impact;Urgency;Priority;Follow up;Assignment gro up;Assigned to;Queue Manager;Backup Queue Manager;Affects Patient Safety;Patient Safety Tracker #;Patient Safety Notes;Describe any actual/potential patient harm;Initiative;Short Descrip tion;Description;Affected System Name / EE Number / Hostname;Non-VA Partner";
n = split(titleList,arr,";");
for (i = 1; i <= n; i++) {
title = arr[i];
titleArr[title] = i;
titleXArr[i] = title;
}
}
{
if ($0 == "===") {
next
}
if ($0 == "Number") {
getline;
num = $0;
next;
}
if (titleArr[$0]) {
title = $0;
getValue(num, title);
next
}
if (length(ss[num, title])) {
ss[num, title] = ss[num, title] " " $0
# print "ss[" num "," title "]= " $0
}
}
END {
n1 = asorti(ss, sortedSS);
print "n1 = " n1;
for (i = 1; i <= n1; i++) {
sub1 = sortedSS[i];
n2 = asorti(ss[sub1],sortedSS2);
print " n2 = " n2;
for (j = 1; j <= n2; j++) {
sub2 = sortedSS2[j];
print "a,b = ? " sub1 "," sub2 " = " ss[sub1, sub2];
}
}
}
On 5/4/2022 2:11 PM, solitary....@gmail.com wrote:
I'm trying to parse a 2-dimensional array and I'm getting the message "fatal: asorti: first argument not an array;" on the line "n2 = asorti(ss[sub1],sortedSS2);".
ss is the original 2-dimensional array. Not sure why it thinks that ss[sub1] is not an array.
Appreciate in advance the effort to show me what I'm missing.Please reduce your code to a minimal example that demonstrates the
problem and provide concise, testable sample input and expected output
so it's easiest for us to help you.
Ed.
On 04.05.2022 21:11, solitary....@gmail.com wrote:
I'm trying to parse a 2-dimensional array and I'm getting the message "fatal: asorti: first argument not an array;" on the line "n2 = asorti(ss[sub1],sortedSS2);".
ss is the original 2-dimensional array. Not sure why it thinks that ss[sub1] is not an array.
Appreciate in advance the effort to show me what I'm missing.You seem to intend using true multidimensional arrays (a[x][y]), but
in your code I see awk's old style array emulations (a[x,y]), like
ss[num, title] " " $0
The indices 'num' and 'title' compose to a single associative key concatenated as
num SUBSEP title
In this case using ss[anything] is not an array but a scalar, and
thus
n2 = asorti(ss[sub1],sortedSS2);
reports an error, because ss[sub1] is also a scalar.
Read the GNU Awk manual ("Arrays of Arrays") for all the details.
Janis
Steve
===
The script followings:
# Create task list
#
function getValue(num,title) {
getline;
if (length($0)) {
ss[num, title] = $0;
# print "ss[" num "," title "]= " $0
}
return
}
BEGIN {
PROCINFO["sorted_in"]="@ind_str_asc";
titleList = "Number;Submitted by;Created by;Location;Affected End-user;Affected User Building Number;Affected User Room Number;Telework;Best Contact Method;Affected User Best Fol low-up Phone Number;Category;Subcategory;Created by;Portfolio;Product Line;Affected Service;Affected CI;Contact type;State;On hold reason;Impact;Urgency;Priority;Follow up;Assignment gro up;Assigned to;Queue Manager;Backup Queue Manager;Affects Patient Safety;Patient Safety Tracker #;Patient Safety Notes;Describe any actual/potential patient harm;Initiative;Short Descrip tion;Description;Affected System Name / EE Number / Hostname;Non-VA Partner";
n = split(titleList,arr,";");
for (i = 1; i <= n; i++) {
title = arr[i];
titleArr[title] = i;
titleXArr[i] = title;
}
}
{
if ($0 == "===") {
next
}
if ($0 == "Number") {
getline;
num = $0;
next;
}
if (titleArr[$0]) {
title = $0;
getValue(num, title);
next
}
if (length(ss[num, title])) {
ss[num, title] = ss[num, title] " " $0
# print "ss[" num "," title "]= " $0
}
}
END {
n1 = asorti(ss, sortedSS);
print "n1 = " n1;
for (i = 1; i <= n1; i++) {
sub1 = sortedSS[i];
n2 = asorti(ss[sub1],sortedSS2);
print " n2 = " n2;
for (j = 1; j <= n2; j++) {
sub2 = sortedSS2[j];
print "a,b = ? " sub1 "," sub2 " = " ss[sub1, sub2];
}
}
}
On Wednesday, May 4, 2022 at 2:39:59 PM UTC-5, Janis Papanagnou wrote:
Thanks for the lesson. Didn't realize that sub1, sub2 resulted in a single subscript.
I changed all to [sub1][sub2] and got the same error.
But it printed only a small portion of what it printed before.
Odd.
Steve
On 04.05.2022 22:31, solitary....@gmail.com wrote:
On Wednesday, May 4, 2022 at 2:39:59 PM UTC-5, Janis Papanagnou wrote: Thanks for the lesson. Didn't realize that sub1, sub2 resulted in a single subscript.
I changed all to [sub1][sub2] and got the same error.I'm not sure that would suffice; we'd need to see the whole code
to judge. (Ideally in a reduced version.) You can also print the
_type information_ of the array indices and components at every
occurrence to track or easier find out where a wrong index type
has been used in your code.
But it printed only a small portion of what it printed before.You may (as suggested by Ed) try to reduce the sample. Or use the
GNU Awk debugger to track the issue.
Janis
--- Synchronet 3.19c-Linux NewsLink 1.113Odd.
Steve
[...]
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 793 |
Nodes: | 10 (1 / 9) |
Uptime: | 39:58:47 |
Calls: | 11,106 |
Calls today: | 3 |
Files: | 186,086 |
Messages: | 1,751,478 |