Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use scalar SCALAR in perl language

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the perl language scalar SCALAR how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Perl scalar variable

1. Scalars in perl

1. The representation of integers:

1212e2 # 1200-12 #-121 "20000000 # perl can use an underscore as a delimiter number or 1200000, but it is easy to see the 012 # octal number, the value is 100x1f # hexadecimal, the value is 31 f regardless of case

2. Floating-point numbers are decimals

11.40.3.33.5.4e2 # 540e or 4.5E-2 + or -, e followed by up to one to three digits-

3. Pay attention

Integer: up to 15 bits, truncated after 16 bits

Precision of floating point numbers: exponential range:-309 to 308 if too small is displayed as 0, too large is displayed as 1.#INF

4. Digital operation

Addition, subtraction, multiplication and division +-* /

II. String

Strings in perl must be enclosed in quotation marks, either single or double quotation marks

The following quotes are all strings:

"" daf2325 "" 244626 "'omicsgene'"

Special characters in the string:'"\ for details, see: there is a difference between single quotation marks and double quotation marks

Used for concatenation of strings.

Third, scalar variables

Scalar variables use: $with a letter or underscore starting with $

Case sensitive, unlimited variable length, no keywords, but cannot be repeated with the default variable

Variable naming is composed of uppercase or lowercase letters or numbers or underscores: [a-zA-Z_0-9], avoid using other special characters in variable names; naming variables should have meaning, that is, you can know what the variable stores from the variable names, which is convenient for later code maintenance. In addition, variable names are strictly case-sensitive.

1. Variable assignment and interpolation, variable assignment with =

$var = "str"; # assign print "this is $var" # interpolation;-> 'this is str "

Perl follows the longest match. When both $var and $varing exist, print "varing", match $varing does not match $var

To match $var, you need to do this: $(ls) in ${var} ing sh

two。 Escape character

\ t indicates that tab is blank

\ n represents a newline character

3.\ the function of

Function: escape character

Cancel the meaning of the character:

Cancel the variable identification of $print "the\ $var is $var\ n"

Cancel the double quotation marks "print" A quote\ "in a string\ n"

Cancel the backslash\ print "A quote\\ in a string\ n"

\ nnn (n for numbers) octal ACSII code print "\ 045"

\ xnn (n for numbers) ACSII code print "\ x45" in hexadecimal representation

4. Single quotation mark

No variable substitution

No escape

The string can wrap the line 'sadas'

Esdadad'

\ the function of:

Cancel the meaning of single quotation marks

Cancel when there is a meaning

5. Special representation of string

Qq (string in qq) # two Qs represent double quotation marks, that's it-- > "string in q" Q (string in q) # A Q represents single quotation marks, that's this-- > 'string in Q'

The advantage is that if there are single or double quotation marks in the string, there is no need to comment out with backslashes.

() can be replaced with paired characters such as {}, [] and so on: [string [in] Q] [string Q] is also possible.

You can also do this: qq/string in Q / qq;string in Q

6. Initial value of variable

The uncreated status is undef, and the end of the file is also undef.

Usage:

The description variable is undefined: undef $a

Used in conditional judgment: if (undef $a)

Instead of the variables you don't care about: $a = "a:b:c:d"; ($A1 recordings undefencedd1) = split (/: /, $s); # this will save a little bit of memory

If you have a undef variable and you don't know where it is, you can add the-w parameter to prompt: #! / usr/bin/perl-w

If created, the created state is defined, which is generally used in condition judgment if (defined $a)

The initial value of the integer is 0 and the initial value of the string is the empty string "".

7. Correlation function

Length () string length, digit number

Trigonometric function sin, mathematical function sqrt, randomly generated function rand,srand

Uc lc ucfrist lcfrist case

Substr index pos string index, location

Conversion function ord,chr,pack,unpack

$lastchar=chop (str) truncates the last character, no matter what character

$result=chomp (str) truncates the end of the line separator (\ n), which can be defined by $/. For example, $/ = "ab" cut off the ab at the end.

Thank you for reading this article carefully. I hope the article "how to use scalar SCALAR in perl language" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report