SHARYA...::Util(3pm)
π NAME π
okay bestie so this is SHARYANTO::Array::Util β array-related utilities, and the manual page itself is filed under SHARYA...::Util(3pm) (the name got squished, don't worry about it, it's iconic that way). It's a Perl module and it is here to make arrays do cute things. π
πΈ VERSION πΈ
This document describes version 0.77 of SHARYANTO::Array::Util (from Perl distribution SHARYANTO-Utils), released on 2015-09-04. vintage but still serving π
β¨ SYNOPSIS β¨
use SHARYANTO::Array::Util qw(match_array_or_regex split_array);
match_array_or_regex('bar', ['foo', 'bar', qr/[xyz]/]); # true, matches string
match_array_or_regex('baz', ['foo', 'bar', qr/[xyz]/]); # true, matches regex
match_array_or_regex('oops', ['foo', 'bar', qr/[xyz]/]); # false
my @res = split_array('--', [qw/--opt1 --opt2 -- foo bar -- --val/]);
# -> ([qw/--opt1 --opt2/], [qw/foo bar/], [qw/--val/])
my @res = split_array(qr/--/, [qw/--opt1 --opt2 -- foo bar -- --val/], 2);
# -> ([qw/--opt1 --opt2/], [qw/foo bar -- --val/])
my @res = split_array(qr/(--)/, [qw/--opt1 --opt2 -- foo bar -- --val/], 2);
# -> ([qw/--opt1 --opt2/], [qw/--/], [qw/foo bar -- --val/])
my @res = split_array(qr/(-)(-)/, [qw/--opt1 --opt2 -- foo bar -- --val/], 2);
# -> ([qw/--opt1 --opt2/], [qw/- -/], [qw/foo bar -- --val/])
like look at those return values, the way they just work π₯
π DESCRIPTION π
no description text up here bestie, the whole personality lives in the FUNCTIONS section right below. scroll, it's worth it π«Ά
π FUNCTIONS π
π¦ match_array_or_regex($needle, $haystack) -> any
Check whether an item matches (list of) values/regexes. vibe check for your data, basically β¨
Examples:
match_array_or_regex("abc", ["abc", "abd"]); # -> 1
match_array_or_regex("abc", qr/ab./); # -> 1
match_array_or_regex("abc", [qr/ab./, "abd"]); # -> 1
This routine can be used to match an item against a regex or a list of strings/regexes, e.g. when matching against an ACL. (yes, ACL like access control list, not the other thing π)
Since the smartmatch (~~) operator can already match against a list of strings or regexes, this function is currently basically equivalent to:
if (ref($haystack) eq 'ARRAY') {
return $needle ~~ @$haystack;
} else {
return $needle =~ /$haystack/;
}
Arguments (* denotes required arguments):
haystack*=>re|str|array[re|str]needle*=>str
Return value: (any)
π¦ match_regex_or_array($needle, $haystack) -> any
Alias for match_array_or_regex. same girl, different name, no cap π
Examples:
match_regex_or_array("abc", ["abc", "abd"]); # -> 1
match_regex_or_array("abc", qr/ab./); # -> 1
match_regex_or_array("abc", [qr/ab./, "abd"]); # -> 1
This routine can be used to match an item against a regex or a list of strings/regexes, e.g. when matching against an ACL.
Since the smartmatch (~~) operator can already match against a list of strings or regexes, this function is currently basically equivalent to:
if (ref($haystack) eq 'ARRAY') {
return $needle ~~ @$haystack;
} else {
return $needle =~ /$haystack/;
}
Arguments (* denotes required arguments):
haystack*=>re|str|array[re|str]needle*=>str
Return value: (any)
π¦ split_array($str_or_re, \@array[, $limit]) => LIST
Like the split() builtin Perl function, but applies on an array instead of a scalar. It loosely follows the split() semantic, with some exceptions. yes, "loosely", she said what she said π (so don't assume it's an exact clone, the exceptions are real)
π¦ replace_array_content($aryref, @elems) => $aryref
Replace elements in <$aryref> with @elems. Return $aryref. Do not create a new arrayref object (i.e. it is different from: $aryref = ["new", "content"]).
π¨ bestie, listen: Do not use this function. In Perl you can just use:splice(@$aryref, 0, length(@$aryref), @elems)or even easier:@$aryref = @elems. I put the function here for reminder.
(iconic that the docs are this honest tbh π)
π SEE ALSO π
SHARYANTO
πΈ HOMEPAGE πΈ
Please visit the project's homepage at https://metacpan.org/release/SHARYANTO-Utils.
π§ SOURCE π§
Source repository is at https://github.com/perlancar/perl-SHARYANTO-Utils.
π BUGS π
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=SHARYANTO-Utils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. receipts, bestie, always bring receipts π
π«Ά AUTHOR π«Ά
perlancar <perlancar@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2015 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie β this was perl v5.34.0, dated 2022-06-17, filing itself under SHARYA...::Util(3pm). go forth and slay your arrays πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: libsharyanto-utils-perl 0.77-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libsharyanto-utils-perl 0.77-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libsharyanto-utils-perl 0.77-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsharyanto-utils-perl 0.77-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsharyanto-utils-perl 0.77-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms