I'm pretty new in Given-When statement in perl. I would like to get the same result for $var=0 or 2, any help?
I've tried the following but I get error.
given($var) {
when(0 || 2) { print "bala";}
when(1) {print "blabla";}
default {print "default";}
}
You can shorten it up doing this:
given($var) {
print "bala" when [0,2];
print "blabla" when [1];
default {print "default"}
}
Your original didn't work because "0 || 2" always evaluates to "2"
Got it!
given($var) {
when($_==0 || $_==2) { print "bala";}
when(1) {print "blabla";}
default {print "default";}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.