Trapping errors ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asearle
    New Member
    • Sep 2006
    • 39

    Trapping errors ...

    I am a bit new to Perl and am having trouble trapping errors in script ...

    However, I think that it is just simple syntax issues and hope that someone can point me towards a good HOWTO which might help me ...

    I have a simple system call to a program (SQLPLUS) which works fine. And when I try to induce an error (for example by misspelling sqlplusw), perl recognises the problem and brings a message but doesn't seem to react to my attempts to trap the error.

    Here I have tried both 'die' and 'warn' but it doesn't seem to make any difference. I have also tried to print STDERR but also can't seem to do this.

    Here is a snippet of my code ...

    system("sqlplus w\ \/nolog\ \@myscript.sql" ) || warn("SQLPlus not found");
    sleep(2);
    print "error: ", <STDERR>, "\n";

    As you can see, I am a real newbie but am sure if someone could give me a tip or two or could point me towards a good tutorial, then I would sort it out very quickly.

    Many thanks,
    Alan Searle.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Your best source of information will always be perldoc. I would suggest that you read up on the documentation for the system command to see the ways that they trap errors. Currently your "sleep" command is not serving any purpose at all, so i would suggest that you remove it. It might be possible that you really want an "alarm", but you can look that function up:



    When it comes to modules, I always look in perldoc first, and secondarily on cpan:

    Comment

    Working...