Question

I was trying to execute a macro using perl and i came across the following problem, if the code is

$myObject->{DoCmd}->RunMacro("Delete") or die "Could not run macro\n";

The program would successfully execute including the macro and die saying Could not run macro Why is die acting weird though the execution is successful ? Is there any other method to check if the macro is executed or not ?

Was it helpful?

Solution

The problem here is that what is being returned by $myObject->{DoCmd}->RunMacro("Delete") evaluates to false in Perl.

When this code is run,

$myObject->{DoCmd}->RunMacro("Delete") or die "Could not run macro\n";

Perl will first run the code on the left side of the or. If it evaluates to false, then it will evaluate the code on the right (which makes the program die).

Here is a quote from perldoc about falsehood in Perl :

The number 0, the strings '0' and "" , the empty list () , and undef are all false in a boolean context. All other values are true. Negation of a true value by ! or not returns a special false value. When evaluated as a string it is treated as "" , but as a number, it is treated as 0. Most Perl operators that return true or false behave this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top