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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
die after open

 



coolkille
Novice

Oct 29, 2004, 2:49 AM

Post #1 of 2 (869 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


davorg
Thaumaturge / Moderator

Oct 29, 2004, 6:45 AM

Post #2 of 2 (867 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:


Code
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
http://www.dave.org.uk/
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