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.
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
Properties
Methods
Operators
Member Details
Scalar Constructor
public Scalar (Interpreter context, int value)
Creates a new scalar with an integer value.
Parameters
public Scalar (Interpreter context, double value)
Creates a new scalar with a double value.
Parameters
public Scalar (Interpreter context, string value)
Creates a new scalar with a string value.
Parameters
public Scalar (Scalar value)
Creates a new scalar with the same value of the given scalar.
Parameters
Remarks
The scalar is created in the context of value
|