📜  珀尔 |标量

📅  最后修改于: 2022-05-13 01:55:46.463000             🧑  作者: Mango

珀尔 |标量

标量是一次存储单个数据单元的变量。标量变量将存储的数据可以是不同的类型,如字符串、字符、浮点、一大组字符串,也可以是网页等。
例子 :

Perl
# Perl program to demonstrate
# scalars variables
 
# a string scalar
$name = "Alex";
 
# Integer Scalar
$rollno = 13;
 
# a floating point scalar
$percentage = 87.65;
 
# to display the result
print "Name = $name\n";
print "Roll number = $rollno\n";
print "Percentage = $percentage\n";


Perl
# Perl program to demonstrate various types
# of numerical scalar variables
 
# Positive integer numerical
# scalar variables
$intpositive = 25;
 
# Negative integer numerical
# scalar variables
$intnegative = -73;
 
# Floating point numerical
# scalar variables
$float = 23.5;
 
# In hexadecimal form
$hexadec = 0xcd;
 
# to display the result
print "Positive Integer = $intpositive\n";
print "Negative Integer = $intnegative\n";
print "Floating Point = $float\n";
print "Hexadecimal Form = $hexadec\n";


Perl
# Perl program to demonstrate various types
# of string scalar variables
 
# String scalar
$alphastring = "GeeksforGeeks";
$numericstring = "17";
$alphanumeric = "gfg21";
 
 
#special character in string scalar
$specialstring = "^gfg";
 
# in single quotes
$singlequt = 'Hello Geeks';
 
# To display the result
print "String with alphabets = $alphastring\n";
print "String with numeric values = $numericstring\n";
print "String with alphanumeric values = $alphanumeric\n";
print "String within Single quotes = $singlequt\n";
print "String with special characters = $specialstring\n";


输出 :

Name = Alex
Roll number = 13
Percentage = 87.65

数值标量

数值标量变量包含整数、整数(正数和负数)、浮点数(包含小数点)等值。下面的例子演示了 perl 中不同类型的数值标量变量。
例子 :

Perl

# Perl program to demonstrate various types
# of numerical scalar variables
 
# Positive integer numerical
# scalar variables
$intpositive = 25;
 
# Negative integer numerical
# scalar variables
$intnegative = -73;
 
# Floating point numerical
# scalar variables
$float = 23.5;
 
# In hexadecimal form
$hexadec = 0xcd;
 
# to display the result
print "Positive Integer = $intpositive\n";
print "Negative Integer = $intnegative\n";
print "Floating Point = $float\n";
print "Hexadecimal Form = $hexadec\n";

输出 :

Positive Integer = 25
Negative Integer = -73
Floating Point = 23.5
Hexadecimal Form = 205

字符串标量

字符串标量变量保存诸如单词(由不同字符组成)、一组单词或一个段落之类的值。以下示例演示了不同类型的字符串标量变量。
例子 :

Perl

# Perl program to demonstrate various types
# of string scalar variables
 
# String scalar
$alphastring = "GeeksforGeeks";
$numericstring = "17";
$alphanumeric = "gfg21";
 
 
#special character in string scalar
$specialstring = "^gfg";
 
# in single quotes
$singlequt = 'Hello Geeks';
 
# To display the result
print "String with alphabets = $alphastring\n";
print "String with numeric values = $numericstring\n";
print "String with alphanumeric values = $alphanumeric\n";
print "String within Single quotes = $singlequt\n";
print "String with special characters = $specialstring\n";

输出 :

String with alphabets = GeeksforGeeks
String with numeric values = 17
String with alphanumeric values = gfg21
String within Single quotes = Hello Geeks
String with special characters = ^gfg