Perl |标量

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

null

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" ;
print "Roll number = $rollno" ;
print "Percentage = $percentage" ;


输出:

Name = AlexRoll number = 13Percentage = 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" ;
print "Negative Integer = $intnegative" ;
print "Floating Point = $float" ;
print "Hexadecimal Form = $hexadec" ;


输出:

Positive Integer = 25Negative Integer = -73Floating Point = 23.5Hexadecimal 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" ;
print "String with numeric values = $numericstring" ;
print "String with alphanumeric values = $alphanumeric" ;
print "String within Single quotes = $singlequt" ;
print "String with special characters = $specialstring" ;


输出:

String with alphabets = GeeksforGeeksString with numeric values = 17String with alphanumeric values = gfg21String within Single quotes = Hello GeeksString with special characters = ^gfg

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享