The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with ssh or loop (can anyone know the issue) kittusri9 Shell Programming and Scripting 2 05-08-2008 04:32 AM
issue with if loop in perl amitrajvarma Shell Programming and Scripting 4 01-08-2008 08:02 PM
perl problem - why isn't 'die' being called? mjays Shell Programming and Scripting 4 08-13-2007 10:16 PM
perl help with pipes and file handles (simple issue) the_learner Shell Programming and Scripting 1 05-06-2007 02:34 AM
Perl problem (compiling issue) 01000101 Shell Programming and Scripting 3 05-24-2006 07:15 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2007
Registered User
 

Join Date: Apr 2007
Location: london
Posts: 40
perl problem - another 'die' issue.

two things.
  1. why doesn't the 'die' message get displayed - "Error: release log directory creation failed..."?
  2. why does the script name and line number get displayed despite the inclusion of a '\n'. apparently adding a newline prevents this from happening.

Code:
if (! -d "$logdir") {
    use File::Path;
    mkpath "$logdir" || die ("ERROR: release log directory creation failed - $logdir: $!\n");
    print "\nINFO: Directory created - $logdir\n";
}
Code:
the result:

mkdir /build/cm_test_sharee: Permission denied at ./crm.prl line 122
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-14-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,434
If you look at the error more carefully, it is generated by mkpath(), not yours.

From the File::Path manpage:

Quote:
If a system error prevents a directory from being created, then the mkpath function throws a fatal error with Carp::croak . This error can be trapped with an eval block:
As you don't trap the error with eval, the program terminates with the error as expected.
Reply With Quote
  #3 (permalink)  
Old 08-15-2007
Registered User
 

Join Date: Apr 2007
Location: london
Posts: 40
i've now changed the code and it works fine.

Code:
if (! -d "$logdir") {
    use File::Path;
    eval { mkpath($logdir) };
    if ($@) {
        print "\nERROR: release log directory creation failed - $logdir: $!\n";
        exit;
    }
i've just started learrning perl and i'm slowly discovering that it makes things harder and longer. in unix i would have done this in one line.

Code:
[ -d ${LOGDIR} ] || mkdir -p ${LOGDIR} || { echo "\nERROR: release log directory creation failed - ${LOGDIR}"; exit 1; }
thank you cbkihong.
Reply With Quote
  #4 (permalink)  
Old 08-15-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,434
Quote:
Originally Posted by mjays View Post
i've just started learrning perl and i'm slowly discovering that it makes things harder and longer.
Not quite.

Don't you think the perl one you wrote looks a bit more descriptive? Using a module, you have to accept that different modules have different behaviour. That is normal. This is just like the '-c' switch of one command and that of another command means totally different things, and you must accept that.

Learning a new thing, you cannot always expect your knowledge of another environment can translate well to it. Perl is a full-blown programming language, and programs naturally need some structure so that no matter you are writing a 30-line or 30000-line program it will still be a manageable piece.
Reply With Quote
  #5 (permalink)  
Old 08-15-2007
Registered User
 

Join Date: Apr 2007
Location: london
Posts: 40
Quote:
Don't you think the perl one you wrote looks a bit more descriptive?
i agree. despite my complaining i think the perl code looks and somehow feels better.

Quote:
Learning a new thing, you cannot always expect your knowledge of another environment can translate well to it.
i think this is the source of my complaint. i've been writing so many unix shell scripts, it's clouded my acceptance of perl and the fact that it's bound to be different.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0