5.7. Perl scalar

发布时间 :2023-12-11 00:55:03 UTC      

Scalar is a simple data unit.

Scalars can be an integer, floating point, character, string, paragraph, or a complete web page.

The following example demonstrates the simple application of scalars:

5.7.1. Example #

#/usr/bin/perl$age=20;#Integer assignment$name=“Runoob”;#String $Salary=130.50#
floating point numberprint“age=$Age\\n”;print“Name=$Name\\n”;Print 'Salary'
=$salary \\n“;

Execute the above program, and the output is as follows:

Age = 20
Name = Runoob
Salary = 130.5

Digital scalar #

Scalars are usually a number or string, and the following examples demonstrate the use of different types of numeric scalars:

5.7.2. Example #

#!/usr/bin/perl$integer=200;$negative= -300;$floating=200.340;$bigfloat=
-1.2E-23;# Octal 377 , Decimal is 255$octal=0377;# hexadecimal is FF, Decimal is
255$hexa=0xff;print"integer =$integer\\n";print"negative
=$negative\\n";print"floating =$floating\\n";print"bigfloat
=$bigfloat\\n";print"octal =$octal\\n";print"hexa =$hexa\\n";

Execute the above program, and the output is as follows:

integer = 200
negative = -300
floating = 200.34
bigfloat = -1.2e-23
octal = 255
hexa = 255

String scalar #

The following example demonstrates the use of different types of string scalars, noting the difference between the use of single and double quotes:

5.7.3. Example #

#/ Usr/bin/perl $var="String Scalar - Beginner Tutorial!"$ Quote='I am within single quotes-
$var '$ Double="I am within double quotes - $var"$ Escape="Escape characters using - tHello,
World! ; print "var=$var n
=$double n "; print" escape=$escape n ";

Execute the above program, and the output is as follows:

Var=string scalar - rookie tutorial!
Quote=I am within single quotes - $var
Double=I am inside double quotes - string scalar - rookie tutorial!
Escape=Use escape characters - Hello, World!

Scalar operation #

The following example demonstrates the simple operation of scalars:

5.7.4. Example #

#/ Usr/bin/perl $str="hello" 'world'# String connection $num=5+10#
Add two numbers $mul=4 * 5# Multiplying two numbers by $mix=$str$ Num# Connect string and number print "str
=$str n "; print" num=$num n "; print" mix=$mix n;

Execute the above program, and the output is as follows:

str = helloworld
num = 15
mix = helloworld15

Multiline string #

We can use single quotation marks to output multiline strings, as follows:

5.7.5. Example #

#/ Usr/bin/perl $string='Novice Tutorial——
Learning is not only about technology, but also about dreams; Print "$string n";

Execute the above program, and the output is as follows:

Novice Tutorial
——Learning is not only about technology, but also about dreams!

You can also use the syntax format of “here” document to output multiple lines:

5.7.6. Example #

#!/usr/bin/perlprint<<EOF;
Novice Tutorial - Learning not only skills, but also dreams!

Execute the above program, and the output is as follows:

Novice Tutorial
——Learning is not only about technology, but also about dreams!

Special character #

Below, we will demonstrate the application of special characters in Perl , such as \__FILE__ , \__LINE__ , and \__PACKAGE_\_ represent the file name, line number, and package name of the currently executing script.

Note: \_\_ is two underscores, \__ FILE_\_ represents two underscores before and after each.”

These special characters are separate tags and cannot be written in a string, for example:

5.7.7. Example #

#/ Usr/bin/perlprint "file name"\__ FILE_ _ N; Print "line number"\__ LINE N;
Print 'Package Name'\__ PACKAGE_ _ N#
Unable to parse print ' _ FILE _ _ LINE _ _ _ PACKAGE_ _ n';

Execute the above program, and the output is as follows:

File name test.pl
Line number 4
Package name main
__ FILE____ LINE ___ PACKAGE__

V string #

An integer that begins with v, followed by one or more integers separated byperiods, is treated as a string text.

When you want to directly declare the numerical value of each character, thev-string provides a clearer way to construct such strings, unlike the difficult to understand method of "\x{1}\x{14}\x{12c}\x{fa0}" , which can be seen in the following example:

5.7.8. Example #

#!/usr/bin/perl$smile=v9786;$foo=v102.111.111;$martin=v77.97.114.116.105.110;print"smile
=$smile\\n";print"foo =$foo\\n";print"martin =$martin\\n";

Execute the above program, and the output is as follows:

Wide character in print at test.pl line 7.
smile = &#x263a;
foo = foo
martin = Martin

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.