Index of /examples/perl/examples/ex02-variables

Icon  Name                    Last modified      Size  Description
[DIR] Parent Directory - [   ] vartest.pl 18-Mar-2014 17:50 2.2K

RCS examples

RCS examples are provided to assist you in learning the software and the development of your applications on the SCC machines. The instructions provided along with the code assume that the underlying OS is Linux. If these examples are run on a different architecture, the user might need to make some changes to the code and/or the way the program is built and executed.

Perl Code Notes

All Perl code examples on the SCC must include as the first line #!/usr/local/bin/perl which is a special line with the characters #! followed by the path on the system to the Perl executable. If you copy an example to another machine, you may have to edit this line based on where Perl is installed on your system. Perl programs must also have the execute bit set in order to run (done via chmod u+x executable_name).

Other than this special line, any line or part of a line that follows the number sign # character will be treated as a comment.

Variables Example Script

This script shows some examples of Perl's three basic variable types: scalar, array and hash (associative array).

The code is documented and if one executes the script by doing:

    scc1% cd /project/scv/examples/perl/examples/ex02-variables
    scc1% vartest.pl
then it will output:

a = 2
now a = 3
now a = 6
b = 
r = hello
hello goodbye
the array X = 2 3 5
the last index in the array X is 2
array element 0 of X is 2
array element 1 of X is 3
array element 2 of X is 5
array element 7 of X is 
the length of the array X is 3
the value assoicated to a is A
the value associated to b is B
keys = c a b d
value associated to c is C
value associated to a is A
value associated to b is B
value associated to d is D
Note: Research Computing Services (RCS) example programs are provided "as is" without any warranty of any kind. The user assumes the entire risk of quality, performance, and repair of any defects. You are encouraged to copy and modify any of the given examples for your own use.