"Sputnik" help  
Sputnik Help
Language Reference - Classes - Class Magic Functions - Index

Class Magic Functions - Index

Overrides the Index function its purpose is to find the index of a given value for example:

class Cat
{
    my $name;
    Function __Construct($n)
    {
        $name = $n;
    }
    Function __Index($needle, $ignoreCase = false)
    {
        return Index($name, $needle, $ignoreCase);
    }
    Function __RIndex($needle, $ignoreCase = false)
    {
        return RIndex($name, $needle, $ignoreCase);
    }
}

my $felix = new Cat("FELIXFX");
say index($felix, "f");
say index($felix, "x");
say index($felix, "F");
say index($felix, "X");
say index($felix, "f", true);
say index($felix, "x", true);
say rindex($felix, "F");
say rindex($felix, "X");
say rindex($felix, "f", true);
say rindex($felix, "x", true);

// PRINTS
// -1
// -1
// 0
// 4
// 0
// 4
// 5
// 6
// 5
// 6

A full list of all possible magic functions can be found here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org