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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl problem - why isn't 'die' being called?
# 1  
Old 08-13-2007
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?

Code:
if (! -d "$logdir") {
    system "mkdir -p $logdir" || die print "\nERROR: release log directory creation failed - $logdir: $!\n";
    print "\nINFO: Directory created - $logdir\n";
}

the result:

mkdir: "/build/cm_test_sharee/release_logs/crm/crmuat": Permission denied

INFO: Directory created - /build/cm_test_sharee/release_logs/crm/crmuat



thanks in advance,

matt
# 2  
Old 08-13-2007
The system call itself will have to return failure in order for die to be called.
This happens only when the system cannot cannot for a new process.

system returns a value like what wait returns.

consider using backticks - ie,
Code:
`mkdir -p $logdir 2>&1`

# 3  
Old 08-13-2007
Perl and shell have opposite ideas about true and false.
Code:
$true;echo $?
0
$false;echo $?
1
$perl -e 'if(0) {print "true\n"} else {print "false\n"}'  
false
$perl -e 'if(1) {print "true\n"} else {print "false\n"}'
true

# 4  
Old 08-13-2007
ah that makes sense - both replies.

thanks for your help,

matt
# 5  
Old 08-14-2007
from the man pages:
Code:
The return value is the exit status of the program as returned by the wait call.
To get the actual exit value, shift right by eight (see below). See also exec.
This is not what you want to use to capture the output from a command, for that you should use merely backticks or qx//, as described in "`STRING`" in perlop.
Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).

see system - perldoc.perl.org
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to find where functions is called in c

Hello, I need to write a perl script to find where functions is called in c files.. The script should scan the file and find out the function names and then search to see where they are called... Lets for now assume all functions are internal. I don't know where to start :( ... (4 Replies)
Discussion started by: bojomojo
4 Replies

2. Programming

Can perl get a pagename when called from iframe?

how? there is html-page with: <iframe> <!--#exec cgi="perl-script"--> </iframe> so in that perl-script need to delegate the name of html-page why? too lazy for ajax (3 Replies)
Discussion started by: tip78
3 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 process loop isn't running

I'm trying to figure out why the perl process we have running in a loop isn't working. Basically its setup to read our queue from Amazon SQS with the results getting inserted into the db. We are using EC2 for video transcoding and once the conversion takes place our web server hosted outside... (10 Replies)
Discussion started by: kwick6
10 Replies

5. Shell Programming and Scripting

perl problem - another 'die' issue.

two things. why doesn't the 'die' message get displayed - "Error: release log directory creation failed..."? why does the script name and line number get displayed despite the inclusion of a '\n'. apparently adding a newline prevents this from happening. if (! -d "$logdir") { use... (4 Replies)
Discussion started by: mjays
4 Replies

6. 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

7. 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

8. Shell Programming and Scripting

How to determine if a script (perl) was called from a CRON job or commandline

Hi, Is there a way to determine if a Script is called from a CRON job or from a commandline Gerry. (2 Replies)
Discussion started by: jerryMcguire
2 Replies
Login or Register to Ask a Question