PerlSharp : Perl Namespace
Hash

This class represents a Perl hash.

[System.Reflection.DefaultMember(MemberName="Item")]
public class Hash : Value, IDictionary, ICollection, IEnumerable

Remarks

Calling Count on the Hash will throw a NotImplementedException. Perl does not provide a direct way of determining the number of bindings in a hash, so no easy way is provided to the user. One can iterate through the Hash to determine the count, but beware of the hash's single-iterator semantics, described below.

Perl hashes have a funny problem: only one thing can iterate through a hash at a time. Multiple concurrent iterations (iterating through the Hash, its Keys collection, or its Values collection) will interfere with each other. An InvalidOperationException is thrown if this occurs while using an enumerator on the Hash.

The following example creates a new hash in the Perl interpreter's context. It then adds some mappings from strings to integers, and then displays the mapping. Creating hashes this way is only useful for passing the hash to sub and method calls, or as return values from extension objects.

C# Example
Interpreter perl = new Interpreter();

Hash h = new Hash(perl);
int ctr = 0;
foreach (string element in new string[] { "this", "is", "a", "test" }) {
	h[element] = ctr;
}

foreach (Scalar key in h.Keys)
	Console.WriteLine("The Hash Has: {0} => {1}", key, h[key]);
			
Members

See Also: Inherited members from Value.

Constructors
Hash(Interpreter)
Creates a new, empty Hash.
Properties
Item[Value]
Value. Gets or sets the Value that corresponds to the given key.
Item[object]
object. Gets or sets the managed-style value that corresponds to the given key.
Keys [read-only]
ICollection. Returns the keys used in the hash.
Values [read-only]
ICollection. Returns the values contained in the hash.
Methods
Clear()
Clears the hash.
Contains(Value) : bool
Tests whether a key is used in the Hash.
Remove(Value)
Removes a binding from the hash.
Member Details
Hash Constructor
public Hash (Interpreter context)

Creates a new, empty Hash.

Parameters
context
The context within which to create the hash.

Clear
public void Clear ()

Clears the hash.


Remove
public void Remove (Value key)

Removes a binding from the hash.

Parameters
key
The key of the binding to remove.

Contains
public bool Contains (Value key)

Tests whether a key is used in the Hash.

Parameters
key
The key to test.
Returns
Whether the key maps to a value.

Keys
public ICollection Keys { get; }

Returns the keys used in the hash.

Value
A collection containing the keys used in the hash.
Remarks
Beware of the hash's single-iterator semantics.

Values
public ICollection Values { get; }

Returns the values contained in the hash.

Value
A collection containing the values contained in the hash.
Remarks
Beware of the hash's single-iterator semantics.

Item
public Value Item [Value key] { set; get; }

Gets or sets the Value that corresponds to the given key.

Parameters
key
The key whose value is to be returned.
Value
The value corresponding to the key.

Item
public object Item [object key] { set; get; }

Gets or sets the managed-style value that corresponds to the given key.

Parameters
key
The key whose value is to be returned. The key will be converted to a Perl value if necessary.
Value
The value corresponding to the key, converted to a mananged-style object. See Interpreter.Convert(Value).