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

What are the basic syntax of Perl

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you what the basic grammar of Perl, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Basic syntax of Perl

Recently, I have been working on openSUSE's OBS (compiler system), many of which use Perl. And I also feel the need to learn some Perl, when there is a little bit of the foundation of other programming languages, and then learn a language, the introduction is very simple. Perl is so widely used on GNU/Linux that replacing shell scripts in many places will be more flexible, excellent and efficient, and it is necessary to learn it. This article is a study of notes, mostly examples of the use of grammar, there is no explanation. When you plan to study OBS, write another Perl application tutorial according to an application.

Scalar quantity

Scalars are the simplest data type in Perl. Most scalars are numbers (such as 255or 325000000 trillion) or strings (such as hello or Gettysburg addresses).

Figures

The internal format of all numbers in perl is double-precision floating-point numbers.

Floating point number of Perl basic syntax

1.25

255.000

255.0

7.25e45#7.25x10 to the 45th power (a large integer)

-6.5e24#-6.5x10 to the 24th power (a large negative number)

-12e-24#--12x10 to the-24th power (a small negative number)

-1.2E-23# exponent symbols can be capitalized (E)

Integer number

0

2001

-40

two hundred and fifty five

61298040283768

Among them, 61298040283768 can also write:

61_298_040_283_768

Non-decimal integers of Perl basic syntax

The 037 octal number 377, equivalent to the decimal number 255

0xff# hexadecimal digit FF, equivalent to the decimal number 255,

0b11111111# is equivalent to the decimal number 255,

You can use an underscore to indicate:

0x1377_0B77

0x50_65_72_7C

Numeric operator

2, 3, 3, 3, 3, 5.

5.1-2.4pm 5.1-2.4pm 2.7

3-12-12-12-12-36

14/2#14/2,7

10.2/0.3#10.2/0.3,34

10 prime is usually a floating point division, 3.33333.

Perl basic Grammar string

◆ single quotation mark string

'four characters of fred'#: freguency, rpendium, epene, d.

'' # empty character (no characters)

'hello\ n'

Single quotation marks (') followed by a backslash (\) string

The "\ n" in single quotation marks is not treated as a newline character.

◆ double quotation mark string

"barney" # is equivalent to 'barney''

"helloworld\ n" # helloworld, line break

String operator for Perl basic syntax

◆ link operator "."

"hello". "world" # equals "helloworld"

"hello". "world" # is the same as "helloworld"

'helloworld'. "\ n" # is the same as "helloworld\ n"

◆ repeat operator "x"

"fred" x "fredfredfred"

5x4# equals "5" x4, "5555"

Automatic conversion between numbers and strings

In most cases, Perl will automatically convert between numbers and strings when needed. How does it know when it needs a string and when it needs a number? This depends entirely on the operators between scalar values. If the operator (such as +) requires a number, Perl treats the Operand as a number. If the operator requires a string (such as.), Perl treats the Operand as a string. Don't worry about the difference between numbers and strings; with the right operators, Perl will do the rest for you.

The "12" * "3" # * operator requires a number, so the result is 36

The result of "12fred34" * "3" # is still 36, with the following non-numeric parts and the preceding spaces filtered out.

"Z" .5 * is equal to "Z" .35, or "Z35"

These are all the contents of this article entitled "what are the basic grammars of Perl?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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