Finding operating system settings in Perl
Archive - Originally posted on "The Horse's Mouth" - 2008-07-10 06:42:35 - Graham EllisIn Perl, you have a variety of special variables available to you ... preloaded with information in many cases. Some of their names are "special" such as $^O, $^T, $", $/, $! or $_, and others are capitalised such as @ARGV, @ISA, %INC and %ENV.
Here's a snippet of code that checks whether you're running on a Microsoft based operating system through the $^O variable, then splits the PATH environment variable which it gets from the %ENV hash into a series of directories that the operating system searches for executable programs.
$sep = ($^O =~ /^MS/) ? ";" : ":"; # Windows uses ; separator
@pels = split(/$sep/,$ENV{PATH});
The complete code example, which lists out all executable files available to you in alphabetic order, is listed here.