bfdi533 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that fails with errors when I run it outside the debugger but does not fail (no errors) when in the debugger. This is annoying as I do not know how to fix it.
#!/usr/bin/perl use Text::CSV_XS; use IO::File; my $argcount = 0; my $infile = ""; my $arg; my %email; my $em; while (@ARGV) { $arg = shift @ARGV; if ($argcount eq 0) { $argcount++; $infile = $arg; print "Processing: $infile\n"; } } my @rows; my $lineterm = "\r\n"; my $csv = Text::CSV_XS->new ( { eol => $lineterm, binary => 1 } ) # s +hould set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", $infile or die "$infile: $!"; while ( my $row = $csv->getline( $fh ) ) { # $row->[2] =~ m/pattern/ or next; # 3rd field should match $em = lc($row->[22]); if ($em eq "0") { #print "BAD: ".join(":",@$row)."\n"; } #print "Email: $em\n"; $email{$em}++; if ($email{$em} eq 1) { #print "New email: $em\n"; $row->[22] = $em; } elsif ($email{$em} > 1) { $row->[22] = ""; } push @rows, $row; } $csv->eof or $csv->error_diag(); close $fh; open $fh, ">:encoding(utf8)", "out2.csv" or die "out2.csv: $!"; foreach $row (@rows) { my @columns = $csv->fields($row); my $status = $csv->combine($row) or warn($csv->error_input()); my $outstr = $csv->string(); print $fh "$outstr\n"; } close $fh;
I am away from that development server but the error was something like unable to load method in IO::Handle.
Can anyone help enlighten this puzzled monk on why this might be?
Update: Seems like it never fails. I finally got back to my development box and tried this again to produce the errors and pull some sample input, and lo, the errors are now gone. I do not know why this was not working before but I have been working to clean up the input data.
The error was on the while look where I am calling $csv->getline($fh). Would the contents of the line cause an error with the IO stream and cause IO::File to object to the getline method?

Replies are listed 'Best First'.
Re: No errors in debugger?
by Old_Gray_Bear (Bishop) on Feb 07, 2011 at 21:52 UTC
    How are you invoking the debugger? With  perl -d my_script? or /usr/bin/perl -d my_script?

    On my machine(s) perl is the Perl that came with my version of Ubuntu (5.8.8, as I recall). The Perl I do most of my work on is in /usr/local/bin/perl (currently Perl 5.10.1).

    All the Modules I down-load from CPAN end up the the 5.10 hierarchy, so a simple perl -d would get a Module Not Found error...

    ----
    I Go Back to Sleep, Now.

    OGB

Re: No errors in debugger?
by ikegami (Patriarch) on Feb 07, 2011 at 21:24 UTC

    You gave us neither the error message nor the means of recreating the problem.

Re: No errors in debugger?
by ikegami (Patriarch) on Feb 07, 2011 at 22:35 UTC

    I finally got back to my development box and tried this again to produce the errors and pull some sample input, and lo, the errors are now gone

    I suspect you were getting

    $ perl -e'STDOUT->print' Can't locate object method "print" via package "IO::Handle" at -e line + 1.

    The reason Perl can't find the method is because you didn't load IO::Handle.

    You would never get that with «use IO::File;» since IO::File loads IO::Handle.