in reply to Re: Parse one fiile, send the records to two different files
in thread Parse one file, send the records to two different files

Thank you both - I was simply copying my last PRINT statement at the end of the script when I was adding the IF/ELSE statement. But now I've run into a new problem - I ran the script after making that simple change and it stopped at record 140, which is the first "error" record in the file (line 4 of my sample code in my original post) and is giving me this message, then stopping - Can't use string ("650187016") as an ARRAY ref while "strict refs" in use at AlterData.pl line 39, <$FH> line 140.
  • Comment on Re^2: Parse one fiile, send the records to two different files

Replies are listed 'Best First'.
Re^3: Parse one fiile, send the records to two different files
by stevieb (Canon) on May 27, 2016 at 16:53 UTC

    Are you still using @$_ in your join statement? ie.

    print $ERR_FH join(',', @$_) for @fields; __^^^__

    If so, remove the @ so that you use the contents of $_ as-is, without attempting to dereference it as an array:

    print $ERR_FH join(',', $_) for @fields; __^^^__
      Well, the script now ran through and again put only the correct files in my "clean" file, but for the error file, I now have 1138 lines, where I should only have 272 lines. When I did a "head" on that error file, I find that it's listing each field as a separate line and no comma delimiters i.e. -

      650187016
      2
      1
      checked out under cash
      650200678
      1
      1
      HIT CASH TWICE
      650096506
      1

      whereas I want the lines put back in their original form, all commas included, i.e.

      650187016,2,1,checked out under cash ,,,,,,,,,,,,,,,,,,,,,,,,,,,,
      Nope! STILL didn't work! Now it jumbled it all the fields from the "error" records together into one just line with spaces and no commas. My errorFiles.csv has just one line with every field from the error records.

      if (!length $fields[28]) { print $ERR_FH join (',', $_) for @fields; } else
      ...is what I'm using. So what else could be missing?

        You need  print $ERR_FH join (',', @fields );


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.

        Does chomp on the array reflect in any change?:

        if (!length $fields[28]) { chomp @fields; print $ERR_FH join (',', $_) for @fields; }
      Wait - never mind! Think I caught what else I left in that statement that caused the problem. Am running it again now to verify.