in reply to Re^8: Split tab-separated file into separate files, based on column name (open on demand)
in thread Split tab-separated file into separate files, based on column name

> apparently a bug in the translator,

Did you try the code?

I think the issue is that awk's arrays are not zero based.

See perltrap#Awk-Traps

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^9: Split tab-separated file into separate files, based on column name (open on demand)

Replies are listed 'Best First'.
Re^10: Split tab-separated file into separate files, based on column name (open on demand)
by haukex (Archbishop) on Aug 29, 2020 at 04:51 UTC
    Did you try the code?

    That's how I discovered the issue... ;-P

    I think the issue is that awk's arrays are not zero based.

    I checked, and older versions of a2p did indeed set $[ = 1; - apparently while having other strange bugs in the output, it looks like to me (at least on my system, the output is strangely chopped up, e.g. "next linine;" or "}tinue {"). After 5.10, a2p dropped the $[ assignment, but added adjustment of array indicies in some places, while not adjusting the array indicies in other places, e.g. for ($i = 1; $i <= $#Fld; $i++) { $Fields[$i] = $Fld[$i]; } became for ($i = 1; $i <= ($#Fld+1); $i++) { $Fields[($i)-1] = $Fld[$i]; }.

Re^10: Split tab-separated file into separate files, based on column name (open on demand)
by jcb (Parson) on Aug 28, 2020 at 23:44 UTC

    Awk does not have numerically-indexed arrays at all. There is a convention for using digit strings to emulate numeric indexing, and like Perl, Awk will convert numbers to digit strings upon demand, but Awk arrays are Perl hashes.

      yes Awk is - similar to JS - using the same datatype for Arrays and Hashes, but ...

      > Awk does not have numerically-indexed arrays at all.

      Awk has implicitly numbered arrays like ARGV

      And ARGV[1] corresponds to $ARGV[0] in Perl

      Similarly will awk's split() index the first element with 1 in the resulting "array".

      And the first field from auto-split is $1 not $0 , while perl -a will put it into $F[0]

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery