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

I am calling a perl script from unix that simply reads in a cvs file and formats it as an xls file. There are instances where a field characters in it that causes perl to cough. In my case it is the inch " character. In my code the parsing problems for these csv records are ignore and written out in the ksh log but not returning a bad status...

else { my $err = $csv->error_input; print "Text::CSV_XS parse() failed on argument: ", $err, "\n"; }

Is there a way to pass this out to unix as a bad status and retain the parsing errors generated in my example?

Edited by planetscape - added code tags and rudimentary formatting

( keep:0 edit:30 reap:0 )

Replies are listed 'Best First'.
Re: Returning a bad status back to the parent UNIX process
by Hue-Bond (Priest) on Jul 27, 2006 at 12:48 UTC
    Is there a way to pass this out to unix as a bad status

    Use exit:

    $ perl -e'exit 42'; echo $? 42
    and retain the parsing errors generated in my example?

    I don't understand this. Aren't errors being written to the ksh log? If you mean to retain the errors within the program, there's no much point in that since if you exit, the program will not be running anymore :^).

    --
    David Serrano

      Thanks David, I would like to hold on the the errors so I'll know what to fix but in my case the xls file is being written out, less the bad records and the unix script doesn't know there is a problem. In my unix scipt I am call the perl scipt using return $? but the status seems to be coming back as a 0 value.

        $? is only useful if you're spawning other processes from Perl, using system, open and others. So if you're not doing this, it's very possible that you're indeed returning a 0 to the calling script. Why don't you return a simple 1 and let the calling script manage the error condition? Better try to post some code for making your problem a bit clearer.

        --
        David Serrano

        I'm not following 100% (more code would be useful). But I think you should print errors to STDERR and in your calling script (or cmdline invoke), redirect STDOUT and STDERR to different files.

        -derby