Every program operates in an Ecosystem. This Ecosystem consists mainly of the operating system and the resources it is connected to.
Each such environment has a usual set of homologous parameters and analogous characteristics. These are usually called the environment variables.
The Perl program (named env.pl) below prints them out from the associative array named %ENV ... Just going through the output is a very good education in OS design - but beyond the scope of this post. But this exercise (even if taken lightly) can be very educative and revealing. Let me give you a small example.
===***===
My Operating System is Windows Vista Home Basic Version.
When I typed the following at the DOS prompt,
D:\perlkit>ver
This is what I got !
Microsoft Windows [Version 6.0.6002]
The Perl Program gave me this
OS=Windows_NT
So is this "Personal PC" OS just a souped up version of an earlier "Group" OS? Should I assume Vista is just really Windows NT under the bonnet (hood) ? I don't know the answer at the time of writing this but my guess is that it probably is. After you visit Google.com, why don't you ask your local Windows Gurus and watch them as they reply to your query. You and they will learn a lot about their expertise, their character, Windows and operating systems in general.
===***===
Just cut and paste the following code and run the program as instructed. Don't worry about the educational commentary affecting the execution of the program. They have been literally "commented out". They are put there on purpose as part of my evil scheme to make you 'read between the lines' of code :-) !
# Each filehandle keeps its own set of values.
# In the case of "$|" , if set to a nonzero value it forces a flush after every write or print.
# Output autoflush. 1=autoflush, 0=default. Applies to currently selected handle.
# Ref : http://www.perlmonks.org/?node_id=353259
# The default output file to which Perl prints is the usual cliched one - the console.
Each such environment has a usual set of homologous parameters and analogous characteristics. These are usually called the environment variables.
The Perl program (named env.pl) below prints them out from the associative array named %ENV ... Just going through the output is a very good education in OS design - but beyond the scope of this post. But this exercise (even if taken lightly) can be very educative and revealing. Let me give you a small example.
===***===
My Operating System is Windows Vista Home Basic Version.
When I typed the following at the DOS prompt,
D:\perlkit>ver
This is what I got !
Microsoft Windows [Version 6.0.6002]
The Perl Program gave me this
OS=Windows_NT
So is this "Personal PC" OS just a souped up version of an earlier "Group" OS? Should I assume Vista is just really Windows NT under the bonnet (hood) ? I don't know the answer at the time of writing this but my guess is that it probably is. After you visit Google.com, why don't you ask your local Windows Gurus and watch them as they reply to your query. You and they will learn a lot about their expertise, their character, Windows and operating systems in general.
===***===
Just cut and paste the following code and run the program as instructed. Don't worry about the educational commentary affecting the execution of the program. They have been literally "commented out". They are put there on purpose as part of my evil scheme to make you 'read between the lines' of code :-) !
===***===
#!/usr/local/ActivePerl-5.6/bin/perl -w
# The above line is relevant only for a posix based OS
# The program is named "env.pl"
# Type as given below into your DOS prompt
# D:\perlkit>perl env.pl > env.txt
# D:\perlkit>start env.txt
use strict;
use warnings;
# This is used to invoke external libraries or modules { eg: import in Java and #include in C }
# There is another similar feature named 'require'. Will cover these 2 separately in another post of this blog
# This is something you do to refresh the state of the system or initialize all variables.
# Something like C:\>cls in DOS | F5 in Windows | INITIALIZE in COBOL
$|=1;
# Something like C:\>cls in DOS | F5 in Windows | INITIALIZE in COBOL
$|=1;
# $| is a "Special variable".
# A special variable always refer to some value pertaining to the currently selected output filehandle# Each filehandle keeps its own set of values.
# In the case of "$|" , if set to a nonzero value it forces a flush after every write or print.
# Output autoflush. 1=autoflush, 0=default. Applies to currently selected handle.
# Ref : http://www.perlmonks.org/?node_id=353259
# The default output file to which Perl prints is the usual cliched one - the console.
print "Here come the variables\n\n";
# Yaawnnn ...
# The "my" used before $var is some sort of namespace legalese which will be expalined in another post..
# If it bothers you, then remove the " my" and the "use strict;" simultaneously.
# The "my" used before $var is some sort of namespace legalese which will be expalined in another post..
# If it bothers you, then remove the " my" and the "use strict;" simultaneously.
foreach my $var (sort keys %ENV)
# Yup! :-) Just like that ... no need to do the usual housekeeping like variable declaration, variable initialization, importing, opening, sorting, iterating, other chori stuff, etc before processing a list - like in the other languages.
# Pretty Cool Huh? Yep We Know !!!
{
# Pretty Cool Huh? Yep We Know !!!
{
print $var . "=" . $ENV{$var} . "\n\n";
}
# %ENV as mentioned earlier is a System Specific Associative Array
# An Associative Array is a list of "key-value" pairs. More on that later in another post!
# %ENV as mentioned earlier is a System Specific Associative Array
# An Associative Array is a list of "key-value" pairs. More on that later in another post!
