perl - Why we can not use "le" in for loop and can use in "if condition" -
i've made program beginner. need clarify something! why m not able use "le" in loop given below i'm able use in "if condition". reason behind that. ?
print "type number upto series should run\n"; $var; $var = int<stdin>; chomp $var; ($i, $t); $x = 0; $y = 1; if($var eq 1) { print "\nyour series : $x\n"; } elsif($var eq 2){ print "\nyour series : $x $y\n"; } elsif($var ge 2) { print "your series : $x $y "; for($i = 1; $i le $var - 2; $i++) { # why condition not working when i'm using "le" # work when i'm using "<=" $t = $x + $y; $x = $y; $y = $t; print "$t "; } print "\n"; } else { print "error: enter valid postive integer\n"; }
you free use le
, <=
like. should aware completely different operators.
numeric comparision operators
== != < <= > >= <=>
the equivalent string comparision operators are
eq ne lt le gt ge cmp
strings , numbers converted each other needed. means example that
3 ge 20 # true: 3 string-greater 20 11 le 2 # true: 11 string-less-or-equal 2
because lexicographic ordering compares character character. using numeric operators when want treat contents of $variables
numbers therefore preferable , yield correct results.
note perl translates between strings , numbers invisibly. advisable use warnings
, helpful message when string can't represent number (e.g. "a"
).
Comments
Post a Comment