To start off with, I realize that I can write an if statement with this operator that compiles and runs. I'm wondering if there's a way it can be used to make an if
/elsif
/else
block a little more elegant.
I currently have a block of code that looks like this
if( $a == $b) {
# Do some stuff
} elsif( $a < $b) {
# Do different stuff
} else {
# Do really weird stuff
}
So there are specific things I want the script to do based on whether the two values are equal, or if they aren't equal, whichever one is lower. It seems like the <=>
operator would be well suited to this.
Aucun commentaire:
Enregistrer un commentaire