On the Unix/linux system, open the command terminal, enter ' Rpm-q Perl ' to see if Perl is installed on the system----on its own CentOS7 system, with Perl software by default:
[email protected]:~/Documents/bash$ rpm -q perl
perl-5.16.3-286.el7.x86_64
You can see that the system has PERL5 software installed by default.
To view the installation location:
[email protected]:~/Documents/bash$ which perl
/bin/perl
[email protected]:~/Documents/bash$ whereis perl
perl: /usr/bin/perl /usr/share/man/man1/perl.1.gz
1. First Perl Program
The Perl statements are separated by semicolons. Comments begin with a # until the end of the line. Statement blocks are enclosed in curly braces. Here is a simple "Hello, world!" program:
#!/usr/bin/perl
print "Hello, world!\n";
Give the script executable permissions, and then execute:
[email protected]:~/Documents/bash$ chmod +x helloworld
[email protected]:~/Documents/bash$ ./helloworld
Hello, world!
The code in the Perl script is not shell commands; they are Perl code. Bash allows the user to combine a series of commands and call it a script, but Perl is not the same as bash. In other words, Perl provides many of the same conventions as bash, such as using apostrophes to get the output of a command.
2. Variables and Arrays
Perl has 3 basic data types: scalar (that is, a unary such as a number and a string), an array, and a hash (hash). A hash is also known as an associative array. The type of the variable is always at a glance, because it is reflected in the variable name: A scalar variable begins with $, the array variable begins with @, and the hash variable starts with a%.
Perl Learning Notes (1)----Getting Started