Sunday, July 19, 2009

VMware Perl toolkit tutorial (2) - basic programing

With VMware Perl installed, we are ready to write VMware perl script. The file extension for Perl scripts is .pl. There are a few elements every Perl script must contain in order to function.
1. The first line of every VMware Perl script is a commented line directed toward the Perl interpreter.
#!/usr/bin/perl
2. Comments can be inserted into a program with the # symbol, and anything from the # to the end of the line is ignored (with the exception of the first line). The only way to stretch comments over several lines is to use a # on each line.

3. Everything else is a Perl statement which must end with a semicolon, like the last line above.

Now let me give you a example.

#!/usr/local/bin/perl
#
# First VMware Perl
#
print 'Hello world.';


4. When the file is executed Perl first compiles it and then executes that compiled version. So after a short pause for compilation the program should run quite quickly. In order to run the Perl program, after you install the Perl,

A:) you can run the program by: perl program or ./program

B:) You can always run the program with warnings using the command by perl -w program. This will display warnings and other helpful messages before it tries to execute the program.

C:) To run the program with a debugger use the command by perl -d progname

No comments:

Post a Comment