Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Utility modules written in Perl, for Perl.

- Author: Ethan Kletschke
- Version: `0.0.5`
- Version: `0.0.6`
- Developed on: Ubuntu (WSL)
- License: MIT
- Project metadata file: [`project.yaml`](./meta/project.yaml)
4 changes: 2 additions & 2 deletions meta/project.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
project-meta:
project-name: PerlUtils
date-started: 2026-10-20
last-updated: 2026-10-31
last-updated: 2026-11-01
languages:
- Perl
status: Experimental
license: MIT
version: 0.0.5
version: 0.0.6

build:
dev-environments:
Expand Down
48 changes: 48 additions & 0 deletions src/lib/Utils/Arrays/Simple.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Utils::Arrays::Simple;

use strict;
use warnings;
use Exporter 'import';

our @EXPORT_OK = qw(
union
);

sub union {
# Parameters
my ($arr1, $arr2) = @_;

# Result array
my @union;
# Hash for tracking elements
my %trackingHash;

# Loop through the first array
foreach my $element (@$arr1) {
# If the element was not previously encountered
if (not exists $trackingHash{$element}) {
# Add a truthy value for that element to the tracking hash
$trackingHash{$element} = 1;
# Push the element to the result array
push @union, $element;
}
}

# Loop through the second array
foreach my $element (@$arr2) {
# If the element was not previously encountered
if (not exists $trackingHash{$element}) {
# Add a truthy value for that element to the tracking hash
$trackingHash{$element} = 1;
# Push the element to the result array
push @union, $element;
}
}

# Return the result array
return @union;
}

1;

__END__
25 changes: 25 additions & 0 deletions src/t/Arrays.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;

use Utils::Arrays::Simple qw(
union
);

subtest "Arrays::Simple" => sub {
subtest "union()" => sub {
my @arr1 = (1, 2, 3, 4);
my @arr2 = (3, 4, 5, 6);

my @res = union(\@arr1, \@arr2);

is_deeply(\@res, [1, 2, 3, 4, 5, 6], "Correctly determines the union");
};

done_testing();
};


done_testing();
1 change: 0 additions & 1 deletion src/t/TextFiles.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env perl

use lib 'lib';
use strict;
use warnings;
use Test::More;
Expand Down
Loading