Home: Perl Programming Help: Beginner:
die after open


Oct 29, 2004, 2:49 AM

Views: 1844
die after open

Hi i have this code and want to use it, but i want it not to die after open if it not finds a file($file)
how do i do that the best way.
--------------------------------------- code start
while ()
foreach my $file (@ListA)
print "\nProcessing: $file";
@tmp = split("/",$file);
open(INPUT,"<$file") || die;


--------------------------------------- code send

Thaumaturge / Moderator

Oct 29, 2004, 6:45 AM

Views: 1842
Re: [coolkille] die after open

(I've moved this to the beginners forum as it's really not an advanced question)

If you don't want your program to die, then don't call the "die" function. I suggest you call "warn" instead.

Along with a few other improvements, your code will then look like this:

while () { 
foreach my $file (@ListA) {
print "\nProcessing: $file";
@tmp = split(m|/|, $file);
open(INPUT, $file) || warn "Can't open $file: $!\n";

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks