Mr. Newb has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks, I'm having some fun reading tab-delimited files created by Microsoft Excel, but interesting things keep happening when I use chomp on the data. I have two files, both created by excel, and seemingly in the same format. However, with the first one, using chomp gives "unitialized value" errors, while with the other, no problemo. Any wisdom on this issue? I'm 99 and one quarter percent sure I'm not supposed to be sharing the data, otherwise I'd be putting up some examples. I'll try to post a copy with some faux data up here later. Thanks!

Replies are listed 'Best First'.
Re: Fun with chomp
by roboticus (Chancellor) on Mar 11, 2013 at 14:53 UTC

    Mr. Newb:

    Since chomp doesn't normally cause problems like that, we'll have to see *some* data to see what's going on. Take a CSV file and chop chunks of it out until you get a small bit that reproduces the error. If there's any confidential data, then scramble it or some such.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Fun with chomp
by Tux (Canon) on Mar 11, 2013 at 15:44 UTC

    Did you trie to read the file with Text::CSV_XS? It does handle tab separated data as exported by Excel fine when instructed to do so (no need for chomps):

    use Text::CSV_XS; open my $fh, "<", "file.tsv"; my $csv = Text::CSV_XS->new ({ binary => 1, sep_char => "\t", auto_dia +g => 1 }); while (my $row = $csv->getline ($fh)) { # … } close $fh;

    Enjoy, Have FUN! H.Merijn
    mod://Text::CSV_XS
Re: Fun with chomp
by toolic (Bishop) on Mar 11, 2013 at 15:02 UTC
Re: Fun with chomp
by Mr. Newb (Acolyte) on Mar 11, 2013 at 16:40 UTC
    Well of course it was my fault, and not perl's. If anyone is interested, excel saves blank cells as the null string...I won't admit my (dumb) mistake, but I think you can figure it out. Anyways, thanks for the help guys
      Or maybe it puts nothing...that sounds more reasonable