How to keep the script from stopping or hanging

N

Nene

Hi,

This script below stops and hangs after it fails to find the directory
in the following code:
chdir("/c\$/$stuff/") || die "cannot cd into /c\$/$stuff ($!)";

Here is the output it gets when it doesn't find the directory:
cannot cd into /c$/blah (No such file or directory) at ./start_blah.pl
line 12, <SCRATCHPAD> line 40.

But I don't want it to stop, I want it to proceed. How do I go about
getting that?


#!/usr/bin/perl -w
print "\n";
print "Starting .....\n";

open(SCRATCHPAD,"LOG.txt") or die "can't open $!";

my @uniq = <SCRATCHPAD>;

foreach my $stuff ( @uniq ) {
chomp($stuff);

chdir("/c\$/$stuff/") || die "cannot cd into /c\$/$stuff ($!)";

open(STARTUP, "/c\$/$stuff/startup |");

system('sleep 10');

}
close(STARTUP);
close(SCRATCHPAD);
 
P

Peter J. Holzer

This script below stops and hangs after it fails to find the directory
in the following code:
chdir("/c\$/$stuff/") || die "cannot cd into /c\$/$stuff ($!)";

Here is the output it gets when it doesn't find the directory:
cannot cd into /c$/blah (No such file or directory) at ./start_blah.pl
line 12, <SCRATCHPAD> line 40.

But I don't want it to stop, I want it to proceed. How do I go about
getting that?

Look up what "die" does.

hp
 
J

Jürgen Exner

Nene said:
This script below stops and hangs after it fails to find the directory
in the following code:
chdir("/c\$/$stuff/") || die "cannot cd into /c\$/$stuff ($!)";

But I don't want it to stop, I want it to proceed. How do I go about
getting that?

Maybe don't tell the script to "die()"?

jue
 
R

Randal L. Schwartz

Nene> chdir("/c\$/$stuff/") || die "cannot cd into /c\$/$stuff ($!)";

Nene> But I don't want it to stop, I want it to proceed. How do I go about
Nene> getting that?

But then it'll be in the wrong directory. The chdir() is there for a
reason, and apparently relatively mandatory, for the original author to
put the die there in the first place.

print "Just another Perl hacker,"; # the original
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top