Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^4: line ending problem Text::CSV alternative Text::ParseWords?

by GertMT (Hermit)
on Oct 06, 2009 at 12:09 UTC ( #799458=note: print w/replies, xml ) Need Help??

in reply to Re^3: line ending problem Text::CSV alternative Text::ParseWords?
in thread line ending problem Text::CSV alternative Text::ParseWords?

aha, I see. Tried this and don't get anything back on the screen. Well except for:

Program exited with code #0 after 0.12 seconds.

This only changes if I open the file data.csv and save it again.

Replies are listed 'Best First'.
Re^5: line ending problem Text::CSV alternative Text::ParseWords?
by ELISHEVA (Prior) on Oct 06, 2009 at 12:31 UTC

    When you say, "I see nothing ... this only changes...", what precisely do you mean? Do you mean you the message goes away and nothing at all prints out? Or do you mean that when the message goes away, you get something printed out, just not the data you expected. Perhaps you are seeing one or more "<>" printed out?

    What happens if you put a print statement in the second code sample, e.g.

    my $line; my @fields; while ( $line = <FILE> ) { print STDERR "<$line>\n"; @fields = &quotewords( ',', 0, $line ) or ( warn "a problem on line $.:$_" ); # rest of code ... }

    If the second loop also prints out nothing, then it would look like your file has no lines in it or your program is dying before it ever gets to the while loop. In rare circumstances, programs can die while doing "print STDERR", but this doesn't normally happen when you are only printing strings. Is this all of your code or do you have some extra material before the while loop?

    The one thing that isn't likely is a problem with line endings. If there were a problem finding the line endings you would get one long line. If there was even one line, even an empty line, the print statement would at least print <>. That is why we made sure there was some non-whitespace in your print statement.

    Are you absolutely sure that the file you are reading in is the file you think you are reading in? Your code is using relative paths. That means it will read the file in the current directory that has the name data.csv. Maybe this is an empty file with the same name as the real csv file? Have you tried running the program using a fully qualified path?

    Best, beth

      this only changes....

      I mean that when I open data.csv and then hit the Save button and close the file and run the script everything works fine and I see the expected output.

      Tried you second suggestion and this kind of works! The expected output is visible in <>.


      The information I see on the screen looks structured. However a more structured way would be even better. I'm having a hard time finding out where to put my print "$id\t$brand\t$color\n"; statement as to have it print this for all records and not only the first line. Thought when I would do it before the closing bracket it would be in the loop? However I must me overlooking something.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799458]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-10-23 20:15 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (88 votes). Check out past polls.