By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

chdir doubt

P: 89

I am using a command as below in my script to change the directory. If the $dir is not available, the program dies.
I want to add some more functionality. For example, I want to send a mail before it dies. How do I do it? I know how to send e-mail but want to know how the existing code canbe changed in order to handle? Before or die in the code? Thanks.

Expand|Select|Wrap|Line Numbers
  1. chdir($dir) or die "Can't chdir to $dir ! \n";
Aug 18 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,059
Expand|Select|Wrap|Line Numbers
  1. chdir($dir) or send_an_email($!);
  3. sub send_an_email {
  4.    my $error = $_[0];
  6.    # here you send the email however you want
  7.    # include $error in the email 
  9.    exit(0);
  10. }
Aug 18 '08 #2

P: 89
ok many thanks for your response.
Aug 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.