Funnily enough nearly all my meditations are inspired by very weird bugs I've found in my or others code. Today I found that code which worked on my home computer just fine didn't work in production. An the fix was simple as replacing 1 with '1'. Now it would take long time to describe the mechanics of that bug but I would like to share with other monks my knowledge about situations when 1 != '1' in Perl.
One of the first things Perl newbies learn is that there is very little difference between numbers and strings in Perl. In most cases you can use 'NNN' and NNN (where NNN is a number) interchangeably in your Perl code. But concerning Perl internals there is a difference: it stores numbers and strings differently and it is possible to distinguish them on the level of internals. Moreover there exist some tricks to check if variable contains a number or a string without resorting to writing C code.
Still usually Perl programmers do not see any difference between numbers and strings but there is very important exception - DBI. When you use placeholders in DBI types of variables may affects how it generates SQL queries. Simple example:
my $sth = $dbh->prepare('SELECT name FROM user WHERE id = ?');
# generates query "SELECT name FROM user WHERE id = 1"
# generates query "SELECT name FROM user WHERE id = '1'"
Well, with most databases and with most field types these two queries are treated as same. However it is not always true - for example if our database is MySQL and field 'id' has 'enum' type these two queries are very different.
Another (a bit MySQL specific) example when the difference between 1 and '1' is critical:
my $sth = $dbh->prepare('SELECT name FROM user LIMIT ?');
# generates query "SELECT name FROM user LIMIT 1"
# generates ILLEGAL query "SELECT name FROM user LIMIT '1'"