Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: print line not showing up

by thezip (Vicar)
on Oct 29, 2007 at 16:59 UTC ( #647880=note: print w/replies, xml ) Need Help??

in reply to print line not showing up

How are you reading the CSV? You might want to use Text::CSV_XS, and check the status after reading each line, as in:

#!/perl/bin/perl use strict; use warnings; use Text::CSV_XS; my $csv = Text::CSV_XS->new( { binary => 1 } ); my $infile = "foo.txt"; open(IFH, "<", $infile) or die "Could not open infile for reading.\n"; while(my $line = <IFH>) [ my $success = $csv->parse($line); if ($success) { ... stuff it in your hash ... } else { ... complain about it ... } } close IFH;

This splits the troubleshooting in half, since it's not clear whether the problem arises from the CSV parsing or in the hash insertion.

Good luck!

Where do you want *them* to go today?

Replies are listed 'Best First'.
Re^2: print line not showing up
by Anonymous Monk on Oct 30, 2007 at 14:46 UTC
    I currently use this:

    open(INFILE,"<$cvsDir/$file") || die("can't open datafile $file: $!"); $csv = Text::CSV_XS->new(); while(<INFILE>) { $status = $csv->parse($_); if ($status == 0) { $bad_argument = $csv->error_input(); print "\t\tBad Argument: $bad_argument\n"; exit; } ... stuff it in my hash ...

    1.) I use Text::CSV_XS, but without the { binary => 1 }, does that make a big difference? What is the { binary => 1 } expected to help to my problem? *)

    2.) I thought my CSV parsing was okay, because the expected content shows up in my debug print lines? I even thought the hash *insertion* was okay, for the same reason?

    *) I tried that at the moment, it doesn't change anything.

      Per the Text::CSV_XS docs, by turning on "binary", it allows the parser to accept a wider range of characters. "To cover the widest range of parsing options, you will always want to set binary."

      I just was not making any assumptions about the data that you are trying to parse.

      Given that, I'd say your next step would be to isolate which specific lines are failing. You can do this by writing the good lines into one file, and if possible, the bad lines into another file. If you can't write the bad lines into another file, then you'll have to determine which lines are missing from the good file.

      To aid in this process, you might prepend a unique index (source line # ?) to the beginning of each line.

      Where do you want *them* to go today?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://647880]
[Discipulus]: the most common in Eataly, for males is to touch twice his own balls

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-04-26 09:52 GMT
Find Nodes?
    Voting Booth?