Using

From Sputnik Wiki
Jump to: navigation, search

Contents

Using

Description

Executes the expressions then runs the code within the statements and finally automatically runs unset() on each expression in the expressions list (Basically cleaning up after you).

using( <expressions> )
{
    statements
    ...
}

Parameters

expressions

A list of expressions to execute separated by ,

Remarks

None.

Example

Example on a simple string:

my $cat = "yyy"; // String exists
using( $cat ) // using will use the string
{
	println("str is: $cat"); // prints the string just fine
}
println("Final: $cat"); // nothing... the string no longer exists...

Example of using it with a class that will be deleted after the using block ends:

using( $newString = new CString("meow") )
{
	println("Hello world!: " . $newString);
}
// Immediately after the using block finishes the class gets unset() and its __Destruct will be run.

You can also stack them example:

my $cat = "yyy";
using( $cat, $newString = new CString("meow"), $coolstring = new CString("moo") )
{
	// the $cat and both class variables get unset once this block ends
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox