Perl Learning Notes (1)----Getting Started

Source: Internet
Author: User
Tags scalar perl script



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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.