Loading ...
Sorry, an error occurred while loading the content.

Looping through an array by element

Expand Messages
  • dachner2002
    The goal is to find out if any columns in a CSV have no data. The number of columns will be unknown. Here s how I m getting the file into an array @recs.
    Message 1 of 1 , May 9, 2008
    • 0 Attachment
      The goal is to find out if any columns in a CSV have no data. The
      number of columns will be unknown.

      Here's how I'm getting the file into an array @recs.

      $mil="c:/production/work/tool.txt";
      open MIL, $mil or die "Cannot open input file for read :$!";

      while (<MIL>)
      {
      $_=substr($_,0,200);
      @recs=split /,/,$_;
      }

      Example CSV file with elements[1],elements[2],elements[3] without data:

      $AT0000634076-VIE,,,,$RDU-VIE
      $AT0000726435-VIE,,,,$HTE-VIE
      $AT0000726443-VIE,,,,$CTE-VIE
      $AT0000726450-VIE,,,,$PTE-VIE
      $AT0000726476-VIE,,,,$CXE-VIE
      $AT0000802079-VIE,,,,$RDX-VIE


      I can't figure out how to loop through the array and sum the columns.

      If I can loop through, I'll use this: $l=$l+length($recs[$i]); and if
      it has a zero value, then that column has no values.

      I've tried foreach but that seems to make an element out of a record.

      Any help appreciated.

      Don
    Your message has been successfully submitted and would be delivered to recipients shortly.