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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Noob question about precedence and exit status

Status
Not open for further replies.

jb53403

Programmer
Jun 23, 2010
3
US
I'm trying to find out why a particular Perl script is experiencing errors on a move command. Here's the line that's erroring:

move( "$file", "$homeDir/trash/" ) or $err1 = "Y";

I want to capture the exit status of the move command, but still make sure the err1 variable gets set to Y, since there's logic built around that in the script. Can I do something like this?

move( "$file", "$homeDir/trash/" ) or ( $err1 = "Y" and print $? );

Otherwise what's the best way for me to accomplish this? Thanks!
 
Where are you getting the move function from? Have you checked the documentation for the appropriate package?
 
I'm guessing you got it from File::Copy, in which case:
perldoc File::Copy said:
RETURN
All functions return 1 on success, 0 on failure. $! will be set if an
error was encountered.
So something like this would probably work for you:
Code:
my $status = move( "$file", "$homeDir/trash/" );
unless ($status) {
  print $!;
  $err = 'Y';
}
 
Yes, I should have realized the move command came from File::Copy. Your suggestion worked like a charm. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top