Results 1 to 6 of 6

Thread: Management error in perl

  1. #1
    Join Date
    Jan 2010
    Posts
    161

    Management error in perl

    Here are my concerns:

    In Perl with some module like ftp, dbi; when one method does not work with "or die" can we leave the program.
    or die "Cannot login ", $ftp->message;
    What I want is that if it crashes then I get the error message in my log.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Management error in perl

    The die makes you exit the program, there is also the exit () if you prefer but I do not see what you got against the die.
    Code:
    open my $log_file, '>>', 'path/file_log' or die $_;
    ...
    ... or die print $log_file "Cannot login  $ftp->message";
    You can also say that STDERR (unless this is STDOUT) is your log file and not the screen.

  3. #3
    Join Date
    Jan 2010
    Posts
    161

    Re: Management error in perl

    I use log4perl for log but the thing is that I can not do this, for example, when using
    Code:
    ftp->login("$machine",'test')
          or die "Cannot login ", $ftp->message;
    Actually I do not want my program crashes when it is unable to login; so please remove the die. The problem is that if I remove it how do I know that my program has failed to login? I can use an eval for example:
    Code:
    eval {      
    ftp->login("$machine",'test')
          or die "Cannot login ", $ftp->message;
    if ($@) {
    	$malog->fatal("Login error");exit 1;
    }
    But the worry is how do I know that it occured? Under test every return code of ftp login, its a impossible mission.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Management error in perl

    Use warn instead of die.
    Code:
    ftp->login("$machine",'test')
          or warn "Cannot login ", $ftp->message;

  5. #5
    Join Date
    Jan 2010
    Posts
    161

    Re: Management error in perl

    Agreed but it does not completely solves my problem. The warn will not block my program certainly and I do know how to test it in error. I am obliged to test the return code of each error and return code are different. While the die, when there is an error, occurred in my script. What I would like done, it can detect the error as the die.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Management error in perl

    warn also gives you errors on STDERR just like die. The only difference between these 2 functions is that "warn" do not force the script to stop. If you do not want to write on STDERR, redirect messages to your log file.

Similar Threads

  1. Replies: 5
    Last Post: 16-07-2012, 11:52 AM
  2. Puzzle - External HDD Disk Management Error
    By MrChris- in forum Vista Hardware Devices
    Replies: 3
    Last Post: 16-07-2009, 02:33 AM
  3. Meet Global Management Gurus at Goa Institute of Management (GIM)
    By Career-Minded in forum Education Career and Job Discussions
    Replies: 1
    Last Post: 09-01-2009, 05:21 PM
  4. Replies: 0
    Last Post: 21-11-2008, 11:49 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,716,306,592.20416 seconds with 17 queries