There's more than one way to do things | |
PerlMonks |
Re: Increment avoids warning unexpectedlyby davido (Cardinal) |
on Jun 07, 2006 at 16:36 UTC ( [id://554086]=note: print w/replies, xml ) | Need Help?? |
The pre-increment and post-increment operators are designed to work on strings too. Witness the following:
If my calculations are correct, you should see "abd". So the point is that if you give ++ a string that it can figure out, it will increment it. Thus, non-numeric strings are legal arguments for ++. Now, in your case, you gave the increment operator a string that it couldn't sensibly increment in its non-numeric form, so the ++ operator dropped into numeric form, and incremented 0 to 1. No warning because non-numeric strings are legal in this case. To read more about the ++ operator's "magic", see perlop. Dave
In Section
Seekers of Perl Wisdom
|
|