It is designed to set your module search path. Specifically, it sets the default location (first location checked) the user's local perl/
directory. It not only adds that directory but makes it a new root for @INC
. It does this for every entry in @INC. In a limited access environment such as those that use CPanel this insures you scripts (general cgi) user your modules over any other.
BEGIN means it occurs before any code not in the block.
The first line determines if /home/root/perl
exists and is a directory. If both are true it assigns that to $base_module_dir
, otherwise it assigns <user home>/perl/
to the variable. Remember, in perl you can index a function call directly if it returns a list.
It finds the user's home directory with getpwuid($>)
. getpwuid()
gets user account information for a given user (generally from passwd on a Unix system) and returns it as a list. $>
is the effective user id of the script. The reason for the index of 7 is that is the location of the home directory in the list (and it is the 8th field in passwd if memory serves).
It then prepends ALL entries in @INC
with $base_module_dir
and inserts those modified entries at the front of @INC
. So it's not just adding $base_module_dir
as a directory but is adding that as a new root for all entries in @INC
. That's why it uses map
instead of just adding a single entry.