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

你可能感兴趣的:(String,Integer,perl,Constructor,output,concatenation)