"Sputnik" help  
Sputnik Help
DifferenceWith(<arrays>...)

Description

Modifies the first array to contain elements that do not exist in any of the subsequent arrays and returns true if any differences are found.

Parameters

<arrays>... At least two arrays to compare with each other.

Return Value

Success: Returns true if any differences are found, and the first array is modified to contain elements unique to it.
Failure: Returns false if no differences are found.

Remarks

The DifferenceWith function modifies the first array to include elements that are unique to it, excluding those that are common with any of the other arrays. It returns true if any differences are found and the first array is changed.

This function is useful as a "checker" when you want to track differences in an array. By running DifferenceWith periodically, you can detect whether changes have occurred in the array based on the returned boolean value. If true, it indicates that modifications were made to the first array, signifying the presence of differences.

Make sure to read about the ->> and the =>> operators which are very often used in Linq statements.

Related

Example

Example of usage:

my $a = ["Cat", "Fox", "Dog"];
my $b = ["Fox", "Cat", "Horse"];
my $c = ["Fox", "Cat", "Horse"];

printr $a->>DifferenceWith($b);
printr $b->>DifferenceWith($c);

printr $a;
printr $b;
printr $c;

// PRINTS
// true
// true
// Array
// (
//     [0] => Dog
//     [1] => Horse
// )
// Array
// (
// )
// Array
// (
//     [0] => Fox
//     [1] => Cat
//     [2] => Horse
// )

Example of a little bit of tracking changes:

// Initial arrays
my $a = ["Cat", "Fox", "Dog"];
my $b = ["Fox", "Cat", "Horse"];

// Create a tracker array to monitor differences
my $tracker = $a->>Difference($b);

// Print the initial differences
print "Diff\n";
printr $tracker;

// Clone the initial state of array $a for later comparison
my $tmpA = clone($a);

// Check for differences and changes
if ($tmpA->>DifferenceWith($b) && $tracker != $tmpA)
{
    say "I see a change!";
}
else
{
    say "No changes yet";
}

// Modify array $b
$b[] = "Meow!";

// Clone the modified state of array $a for later comparison
my $tmpA = clone($a);

// Check for differences and changes after modifying $b
if ($tmpA->>DifferenceWith($b) && $tracker != $tmpA)
{
    // Update the tracker with the new differences
    $tracker = clone($tmpA);
    say "I see a change!";
}
else
{
    say "No changes yet";
}

// PRINTS
// Diff
// Array
// (
//     [0] => Dog
//     [1] => Horse
// )
// No changes yet
// I see a change!

 


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