perl problem - another 'die' issue.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl problem - another 'die' issue.
# 1  
Old 08-14-2007
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

# 2  
Old 08-14-2007
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.
# 3  
Old 08-15-2007
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.
# 4  
Old 08-15-2007
Quote:
Originally Posted by mjays
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.
# 5  
Old 08-15-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FTP Connection die out

Hi, I will ftp aroung 80 files after connecting to an FTP Server. But after 2 minutes of connection, it is timed out and connection is dying. Server had a 2 minute connection timeout if connection is idle. But my question, Isn't tranfering files not considered as an activity. Is the connection... (7 Replies)
Discussion started by: vasuarjula
7 Replies

2. Post Here to Contact Site Administrators and Moderators

Tynt Tracer Must Die

First of all, I want to thank everyone who runs this forum for the fine job they've done. While I myself have not yet had any need for help, I have enjoyed and learned while helping others. Due diligence disclaimer: I searched for a discussion on this issue, using "tynt" and "copy paste", but... (11 Replies)
Discussion started by: alister
11 Replies

3. Shell Programming and Scripting

Read from a pipe or die in perl

I have a perl program that I want to read from a file passed as an argument or from a pipe. If their is no pipe or arguments, I want it to output a help message. I am stuck on how to prevent perl from reading from the keyboard if it isn't fed any file names or data from a pipe. The only things I... (4 Replies)
Discussion started by: ilikecows
4 Replies

4. Shell Programming and Scripting

perl problem - why isn't 'die' being called?

last week i started learning perl, so have limited skill and knowledge. why isn't 'die' being called and the script exiting before the 'directory created' line? if (! -d "$logdir") { system "mkdir -p $logdir" || die print "\nERROR: release log directory creation failed - $logdir: $!\n";... (4 Replies)
Discussion started by: mjays
4 Replies

5. UNIX for Dummies Questions & Answers

Python 2.5 must die.

I am using SunOS 5.7 I have installed Python 2.5 via make install Without going into details, I'd like to uninstall it and replace it with an earlier version. Maybe as far back as 2.2.3. Unfortuantely, make uninstall gives me Don't know how to make target 'uninstall'. This is thematically... (2 Replies)
Discussion started by: Dbecker
2 Replies

6. Solaris

what time did my process die ??

Hi there I have a backup script that runs every night and for some reason ive been getting in in the morning and the process has died, Is there any way I can tell when it died? if not .....would anybody recommend some scripting that i could do that would be able to tell me this information ... (3 Replies)
Discussion started by: hcclnoodles
3 Replies

7. News, Links, Events and Announcements

Live Free or Die!

Mods: Delete this if you think that this is not appropriate. I found this rather amusing. If you go to www.unix.net now you will see the OpenGroup selling license plates that read "Live Free or Die/Unix/Unix is a trademark of the OpenGroup" (http://www.unix.net/unix_plates.html) I just... (12 Replies)
Discussion started by: auswipe
12 Replies
Login or Register to Ask a Question