I’m having quite a difficulty, figuring out some strange behavior when looping through symbols in Perl, using the for loop.
This code snippet works just as expected:
for (my $file = 'a'; $file le 'h'; $file++) {
print $file;
}
Output: abcdefgh
But when I try the loop through the symbols backward, like this:
for (my $file = 'h'; $file ge 'a'; $file--) {
print $file;
}
gives me the following as a result.
Output: h
Maybe the decrement operator doesn’t behave as I think it does when symbols are involved?
Does anybody have any ideas on the matter? I’d really appreciate your help!
Regards,
Tommy
The auto-decrement operator is not magical, as per perlop
You can do something like this though: