in reply to Re: Split Tab separated text file into valid and invalid records
in thread Split Tab separated text file into valid and invalid records

this is very helpful. Is it possible that I can get some code to start with, I am just starting Perl and have done this so far.
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] or die "Need to get CSV file on the command line\n +"; open (FILE, $file); while (<FILE>) { chomp; ($emp, $dt, $account, $baldue, $credit, $netarrears, $locno, $devno, +$parkbal, $rentnoretro, $maintbal, $legbal, $otherbal, $retrobal, $chu, $mk, $bu +ildno, $mo veoutdt, $status, $legal, $legdt) = split("\t"); print "$dt $account $baldue $credit $netarrears $locno\n"; }
  • Comment on Re^2: Split Tab separated text file into valid and invalid records
  • Download Code

Replies are listed 'Best First'.
Re^3: Split Tab separated text file into valid and invalid records
by ww (Archbishop) on Sep 23, 2013 at 13:38 UTC
    Close!

    (Assuming parent post is by OP, Ma): you have a space inside the name of one of your variables, $mo veoutdt. But that's harder than need be to spot, since you failed to follow the guidance at the text-input box, namely -- use code and para tags.

    As to your other code problems, you've invoked strict,(and, very wisely), but without honoring one of its key strictures, declaring variables with a my (or our etc). The error messages should have given you a direction to repair the problem, though there were so many you may have found them overwhelming (go forth and sin no more).

    Here's your code, modified to use data rather than a file and truncated for simplicity and clarity:

    #!/usr/bin/perl use strict; use warnings; my ($dt, $account, $baldue); while (<DATA>) { chomp; ($dt, $account, $baldue) = split /\t/; # shorter, more standard. + was: split("\t"); print "$dt | $account | $baldue \n"; } =head OUTPUT 4-11-13 273.13 273.13 20130512 11.17 36.14 09222013 2,479.00 6,481.16 =cut __DATA__ 4-11-13 273.13 273.13 20130512 11.17 36.14 09222013 2,479.00 6,481.16
      Awsome, Thank you everyone.
Re^3: Split Tab separated text file into valid and invalid records
by hdb (Monsignor) on Sep 23, 2013 at 13:23 UTC

    Check the documentation of the modules I recommended. There is some sample code there.

    Also please use code tags to make your posts more readible.