How To Determine Installed Modules

August 27, 2003

Here’s how to determine what modules have been installed after the original Perl installation, hence showing those modules not part of the core installation. Type this from a command line:


perldoc perllocal

How To Tell A Number From A String

August 13, 2003

Often, I need to compare two variables but I don’t know if they are numbers or strings. I need to know the type so I can pick the proper comparison operators, i.e., == or eq, > or gt.
So, here’s how to do it:


~$x ne ~"$x" ? 'numeric' : 'string'

~ is the bitwise negation operator (see perlop). It does not negate integers and strings in the same way.

Examples:


$ perl -e 'print ~1, "\n"'
4294967294
$ perl -e 'print ~"1", "\n"'
Œ

(character which ASCII code is 255 - ord(’1′))

Bad Behavior has blocked 14 access attempts in the last 7 days.