Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

how to find out if move succeeds?

by smanicka (Scribe)
on Feb 25, 2009 at 17:43 UTC ( [id://746329]=perlquestion: print w/replies, xml ) Need Help??

smanicka has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

i have a code like this:

if(-e "$newlocationlocation"){ move ($oldlocation,$newlocation) or warn "failed to move to folder"; print LOGFILE "$theTime,moved,$oldlocation,$folder\n"; } else{ my $perm=775; mkdir ($newlocation,$perm) or &on_err("Error making Directory\n"); move ($oldlocation,$newlocation) or warn "failed to move to folder"; print LOGFILE "$theTime,moved,$oldlocation,$folder\n"; }
I actually need to be able to write different stuff into the log based on whether the move succeeds or not.How can I do that?

thanks

Sandhya

Replies are listed 'Best First'.
Re: how to find out if move succeeds?
by Roy Johnson (Monsignor) on Feb 25, 2009 at 17:48 UTC
    You already test the result of move, you just don't change what your log writes. You also duplicated code in both branches of the if. I think it ought to go something like this:
    if (not -e $newlocationlocation) { my $perm = 775; mkdir ($newlocation,$perm) or &on_err("Error making Directory\n"); } if (move ($oldlocation,$newlocation)) { print LOGFILE "$theTime,moved,$oldlocation,$folder\n"; } else { warn "Failed to move to folder"; print LOGFILE "$theTime,failed to move,$oldlocation,$folder\n"; }

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://746329]
Approved by kennethk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-16 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found