On Sun, Dec 19, 2021 at 7:14 AM Ovid via perl5-porters < perl5-porters@perl.org> wrote: > The if/else is actually pretty simple if we step back for a moment. I > think the confusion is that we misunderstand what an "else" block means in > Perl. Let's consider this: > > if ( $var > 3 ) { > ... > } > else { > ... > } > > In the above, in the else block, we mentally assume that "$var <= 3" > holds. In many statically typed languages, that assumption might hold true. > > In Perl, $var might be undef and be evaluated as less than three. However, > $var might be the string "Hello, World". $var might also be a reference to > a hash, we get absolutely no warning, and we hit our else block with an > assumption that is probably true ($var <= 3), but not in this particular > case. We _should_ be verifying what kind of data that $var holds, but > usually we don't. > But this isn't really what's going on here. In Perl, every scalar value is a number, once you use it as one. Hash references numify to their refaddr. So this comparison is still perfectly valid and there are no type conflicts, for any scalar value except those which die when numified. -DanThread Previous | Thread Next