• Difficulty in parsing 2-dimensional array

    From solitary....@gmail.com@solitary.wanderer52@gmail.com to comp.lang.awk on Wed May 4 12:11:04 2022
    From Newsgroup: comp.lang.awk

    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];
    }
    }
    }
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Ed Morton@mortonspam@gmail.com to comp.lang.awk on Wed May 4 14:35:09 2022
    From Newsgroup: comp.lang.awk

    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.
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Janis Papanagnou@janis_papanagnou@hotmail.com to comp.lang.awk on Wed May 4 21:39:56 2022
    From Newsgroup: comp.lang.awk

    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];
    }
    }
    }


    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From solitary....@gmail.com@solitary.wanderer52@gmail.com to comp.lang.awk on Wed May 4 13:28:43 2022
    From Newsgroup: comp.lang.awk

    On Wednesday, May 4, 2022 at 2:35:11 PM UTC-5, Ed Morton wrote:
    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.

    A smaller example would have been preferable. Agreed.

    Steve
    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From solitary....@gmail.com@solitary.wanderer52@gmail.com to comp.lang.awk on Wed May 4 13:31:18 2022
    From Newsgroup: comp.lang.awk

    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 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];
    }
    }
    }

    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From Janis Papanagnou@janis_papanagnou@hotmail.com to comp.lang.awk on Thu May 5 00:36:55 2022
    From Newsgroup: comp.lang.awk

    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


    Odd.

    Steve

    [...]


    --- Synchronet 3.19c-Linux NewsLink 1.113
  • From solitary....@gmail.com@solitary.wanderer52@gmail.com to comp.lang.awk on Wed May 4 15:48:09 2022
    From Newsgroup: comp.lang.awk

    The first level subscript is work order and the second level is category. The first batch worked as expected. Then the next work order looked like the previous work order plus some control characters and maybe something more. I pattern matching to only work with work order numbers that were "proper". That fixed the problem.
    Thanks so much. Fixed a script and learned more Awk. Great!!!
    Steve
    ---
    On Wednesday, May 4, 2022 at 5:36:58 PM UTC-5, Janis Papanagnou wrote:
    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


    Odd.

    Steve

    [...]
    --- Synchronet 3.19c-Linux NewsLink 1.113