perl using function return value as if statement condition -
Is it possible to use the return value of the function as an expression in "Fe" statement in Perl? for example; I can write in C
if (! Myfunction ()) {printf ("myfunction false. \"); } Other {printf ("My function has come true \ n"); } But in Perl, I think I should go through pain ..
$ ret = MyFunction (); If (! $ Ret) {Print "myfunction returned incorrectly. \ N"; } As soon as I post it, I know that many other posts in this question will be redirected to me. But, obviously, what I'm looking for, I was not able or I will not write it! Then leave the messages "I have tried to search ...."
Here my performance () looks.
sub myFunction {my ($ run), $ runtime) = @_; Mine ($ code); Eval {$ SIG {ALRM} = all {dead "Operation time out";}; Alarm ($ run_time); $ EXIT_STR = `$ run`; Perform # $ and EXIT_STR $ code = $ ?; Save output in # Save CMD exit code. $ EXIT_CODE = $ code; # Set global values (EXIT_CODE) alarms (0); Return ($ code); }; If ($ @) {if ($ @ = ~ / Operation Time Out /) {Print "Time Out \ n"; Return (10); After everyone's opinion, after reading everyone's opinion, I went back to the books to learn more about Aqual, after reading it, it became clear that the value of the function "eval" was " Back "was part of it. It was for me to decide what to do with the eval result, along with that I made some changes and the function works like I had hoped. Thanks to all!
Yes.
Wait I can not give such a small answer ...
Yes. If a function is inside an I statement, then the return value of the pearl function will be taken as the boolean value. If the return value is zero, an empty string, a blank value, an empty string or an unfinished, then the if statement will be treated incorrectly. Otherwise, the if statement will be considered correct. Examples of examples are easy to understand:
if (is_odd is not ($ number)) {print "$ number is divisible by two \ n"; } Is_odd {my $ number = shift; Return $ Number% 2; # Modulo arithmetic} In the above, $ number% 2 will also return numbers to zero and one odd numbers. This is a good question. The best part is to write a small script to see it. Play around with it:
For example, let's add another function that we can use:
is sub IeEeven {my $ number = shift; Do not return is_odd ($ number); } What is this refund? If it works in a statement?
Comments
Post a Comment