Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return after warn

Status
Not open for further replies.

dissma

IS-IT--Management
Apr 10, 2008
2
SE
Hi,

I am a new to Perl and need help with how to return from a function directly after a warn.

This looks like it works but I am not sure if it is okay to do it this way.
rename($name1, $name2) or warn "Can't rename file $name1: $!, error" and return 0;

Thanks
 
I think your way is OK as long as there is no issure of precedence causing problems. I would probably write it like this though as it seems clearer to me and avoids any precedence problems:

Code:
unless (rename($name1, $name2)){
   warn "Can't rename file $name1: $!, error";
   return 0;
}

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you for pointing that out to me. If the warn for some reason is a failure the return will never be executed. I will do it your way thank you for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top