scalar in perl

scalar in perl-1
example:
@array = qw( zero one two three four five six seven eight nine );

# output the number of elements and the last index number
print "There are ", scalar( @array ),
      " elements in /@array./n";
print "The last index in /@array is $#array./n/n";

# output the last element in the array
print "/@array[ $#array ] is $array[ $#array ]./n/n";

# use negative subscripts to access
# elements from the end of the array
print "/@array[ -1 ] is $array[ -1 ]./n";
print "/@array[ -4 ] is $array[ -4 ]./n/n";

$#array = 10;        # increase the number of elements to 11
print "@array./n";

$#array = 5;         # reduce the number of elements to 6
print "@array./n";

$#array = 10;        # increase the number of elements to 11
print "@array./n";

@array = ();         # remove all elements in the array
print "@array./n";
print "There are now ", scalar( @array ),
      " elements in /@array/n";

Scalars are strings and numbers in Perl.

public class Scalar : Value

Remarks
Scalars are stored by Perl as a string, integer, or double-precision floating point number. But, Perl will convert on the fly between its stored representation and the desired representation. Because the managed world is type-safe, some of this magic disappears when you want to actually access the value of the Scalar, because you must specify in what representation you want the value.
Members

See Also: Inherited members from Value.

Constructors
Scalar(Interpreter, int)
Creates a new scalar with an integer value.
Scalar(Interpreter, double)
Creates a new scalar with a double value.
Scalar(Interpreter, string)
Creates a new scalar with a string value.
Scalar(Scalar)
Creates a new scalar with the same value of the given scalar.
Scalar(Interpreter, object)
Creates a new scalar with the given value.
Properties
DoubleValue
double. Gets/sets the value of the Scalar as a double.
IntValue
int. Gets/sets the value of the Scalar as an integer.
StringValue
string. Gets/sets the value of the Scalar as a string.
Methods
 Append(Scalar)
Appends a string to the end of this Scalar.
 Concat(Scalar) : Scalar
Returns the concatenation of this Scalar and another Scalar.
static Eq(Scalar, Scalar) : bool
Tests for string equality on two Scalars, using the Perl eq operator.
 SetValue(string)
Changes the value of the Scalar to a string.
 SetValue(int)
Changes the value of the Scalar to an integer.
 SetValue(double)
Changes the value of the Scalar to a double.
static StringCompare(Scalar, Scalar) : int
Performs a string comparison on two Scalars, using the Perl string comparison operator.
Operators
Conversion: Perl.Scalar to System.String
Implicitly converts a Scalar to its string value.
Conversion: Perl.Scalar to System.Int32
Implicitly converts a Scalar to its integer value.
Conversion: Perl.Scalar to System.Double
Implicitly converts a Scalar to its double value.
Member Details
Scalar Constructor
public Scalar (Interpreter context, int value)

Creates a new scalar with an integer value.

Parameters
context
The context in which to create the scalar.
value
The initial value of the scalar.

Scalar Constructor
public Scalar (Interpreter context, double value)

Creates a new scalar with a double value.

Parameters
context
The context in which to create the scalar.
value
The initial value of the scalar.

Scalar Constructor
public Scalar (Interpreter context, string value)

Creates a new scalar with a string value.

Parameters
context
The context in which to create the scalar.
value
The initial value of the scalar.

Scalar Constructor
public Scalar (Scalar value)

Creates a new scalar with the same value of the given scalar.

Parameters
value
The scalar that contains the initial value for the new scalar.
Remarks
The scalar is created in the context of value
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值