Config - Access Perl Configuration Information

use Config; if ($Config{cc} =~ /gcc/) {
 print "built by gcc\n";
}
use Config qw(myconfig config_sh config_vars);
print myconfig();
print config_sh(); config_vars(qw(osname archname));

The Config module contains all the information that the Configure script had to figure out at Perl build time (over 450 values).[]

[7] Perl was written in C, not because it's a portable language, but because it's a ubiquitous language. A bare C program is about as portable as Chuck Yeager on foot.

Shell variables from the config.sh file (written by Configure) are stored in a readonly hash, %Config, indexed by their names. Values set to the string "undef" in config.sh are returned as undefined values. The Perl exists function should be used to check whether a named variable exists.

Here's a more sophisticated example using %Config:

use Config; defined $Config{sig_name} or die "No sigs?"; foreach $name (split(' ', $Config{sig_name})) {
 $signo{$name} = $i; $signame[$i] = $name; $i++;
}
print "signal #17 = $signame[17]\n"; if ($signo{ALRM}) {
 print "SIGALRM is $signo{ALRM}\n";
}

Because configuration information is not stored within the Perl executable itself, it is possible (but unlikely) that the information might not relate to the actual Perl binary that is being used to access it. The Config module checks the Perl version number when loaded to try to prevent gross mismatches, but can't detect subsequent rebuilds of the same version.