CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
die after open



Oct 29, 2004, 2:49 AM

Post #1 of 2 (1854 views)
die after open Can't Post

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

Post #2 of 2 (1852 views)
Re: [coolkille] die after open [In reply to] Can't Post

(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


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives