Introduction to perl scalar and operators

Source: Internet
Author: User

1. Perl converts a common variable into a scalar. This variable can refer to two types of direct quantities: Numeric direct quantities and string direct quantities.

A) String Representation Method:
Single quotes: the meaning of strings in single quotes is intuitive. Variable values and escape characters are not required;
Double quotation marks. The variable value and escape character value are required.
If you want to remove it, you usually need to add a backslash before it. The single quotation marks or double quotation marks are also required.

B) In addition, you can use qq or q to replace double quotation marks or single quotation marks, and the delimiters can be paired with (), <>,{}, [], and so on.

2. scalar Variables:

$ Add a variable name (array @, hash structure %); variable name is case sensitive; do not declare before using a scalar, but Initialization is required.

Some special scalar variables:
$ _, $ ", $/, $2, $, $! And their values are generally used as the "default value ". For example, $ _ is used as the default output value. $! Used as the default value of Error.

3. Expressions and operators:

1) Warning in Perl #! /Usr/bin/perl/-w, or use warnings;
2) Digit OPERATOR: Calculate the remainder % except/, and Power 4 ** 3 = 64
3) string OPERATOR: the concatenation operator ($ c = $ a. $ B;) can be used for the interpolation and replacement of variables in double quotation marks. If you cancel the replacement, add a backslash before $. Repeated operator x (for example, $ line = "_" x 7)
4) Name-based operators: int is an integer, length is a length, lc is converted to lowercase, uc is converted to uppercase, rand is a random number from 0 to the parameter value, cos, more perldoc
5). Angle brackets OPERATOR: <> Read a row from the handle. For example, <STDIN> reads a row from the keyboard of the standard input device, <FILE> reads a row from the FILE handle, and chomp $ line; delete the end line break.

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.