Permute(3pm)
β¨ Permute(3pm) β¨
User Contributed Perl Documentation π β yes bestie, that's the vibe, we're in the user-contributed corner of the Perl docs and it is iconic.
πΈ NAME πΈ
String::Glob::Permute</purgle> β expands {foo,bar,baz}[2-4] style string globs. It's giving pattern goes in, every possible hostname comes out. π
π¦ SYNOPSIS π¦
use String::Glob::Permute qw( string_glob_permute );
my $pattern = "host{foo,bar,baz}[2-4]";
for my $host (string_glob_permute( $pattern )) {
print "$host\n";
}
# hostfoo2
# hostbar2
# hostbaz2
# hostfoo3
# hostbar3
# hostbaz3
# hostfoo4
# hostbar4
# hostbaz4
Nine hosts, one lil pattern, zero manual typing. The way that just works?? Obsessed. πβ¨
π DESCRIPTION π
The string_glob_permute() function that this module hands you goes through text strings, finds all the glob-ish notation in them, and gives you back every possible permutation. All of them. No gatekeeping. π
So say you wanna run a script on host1, host2, and host3 β instead of typing all that out like it's 2004, you write:
@hosts = string_glob_permute( "host[1-3]" );
and boom, you get a list of hosts right back: ("host1", "host2", "host3"). Slay. π
π Ranges with gaps π
Not every range is cute and continuous, and that's fine, we support that too β just separate the blocks with commas, bestie:
@hosts = string_glob_permute( "host[1-3,5,9]" );
That will return ("host1", "host2", "host3", "host5", "host9"). See how 4, 6, 7, 8 justβ¦ weren't invited? Periodt. π
π§ Curly brackets, comma-separated strings π§
And finally β the main character move β curly brackets with a comma-separated list of strings, like:
@hosts = string_glob_permute( "host{dev,stag,prod}" );
and you'll get permutations with each of the alternatives back: ("hostdev", "hoststag", "hostprod") back. Every alt gets its moment. β¨
π Combine them all, why not π
All of the above can be combined, so:
my @hosts = string_glob_permute( "host{dev,stag}[3-4]" );
will result in the permutation ("hostdev3", "hoststag3", "hostdev4", "hoststag4"). Look at her go. π
β οΈ The rules, no cap β οΈ
The patterns allow numerical ranges only β [1-3], that's it. No string ranges like [a-z]. And the pattern must not contain blanks.
Fr fr, if you try [a-z] that's not the vibe this module is on. Numerical only, bestie.
The function returns a list of string permutations on success and undef in case of an error. A warning is also issued if the pattern cannot be recognized. So likeβ¦ you will know. π
π Zero padding π
An expression like:
@hosts = string_glob_permute( "host[8-9,10]" );
# ("host8", "host9", "host10")
will expand to ("host8", "host9", "host10"), featuring no zero-padding to create equal-length entries. So 8 and 9 are just out here living their single-digit truth next to 10. No shame in it. π
But if you want ("host08", "host09", "host10") instead β padded, matching, aesthetically consistent, the whole aesthetic β then pad all the integers in the range expression accordingly:
@hosts = string_glob_permute( "host[08-09,10]" );
# ("host08", "host09", "host10")
Pad all of them or none of them, that's the rule. π
π Note on Perl's internal Glob Permutations π
Okay so here's a lil lore drop: there's a little-known feature within Perl itself that does something similar. For example:
print "$_\n" for < foo{bar,baz} >;
will print:
foobar
foobaz
β¦but only if there is no file in the current directory that matches that pattern. Read that again, bestie. That's a big ol' asterisk. π
String::Glob::Permute, on the other hand, expands irrespective of matching files, by simply always returning all possible permutations. It doesn't care about your filesystem. It has no notes. It just permutes. π
It's also worth noting that Perl's internal Glob Permutation does not support String::Glob::Permute's [m,n] or [m-n] syntax. So if that's what you need, you know where to be. π¦
π COPYRIGHT & LICENSE π
Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to the contents of this file are licensed under the Perl Artistic License (ver. 15 Aug 1997). β¨
π AUTHOR π
Algorithm, Code: Rick Reed, Ryan Hamilton, Greg Olszewski. Module: 2008, Mike Schilli <cpan@perlmeister.com> π«Ά
And that's the whole page, bestie. This was rendered from the docs that ship with perl v5.34.0, dated 2022-06-17, and the page itself is Permute(3pm) β so like, shoutout to the people who wrote it and the people who shipped it. Icons, every one of them. βππ
π¦ where this page comes from
- debian bookworm: libstring-glob-permute-perl 0.01-4 Β· Artistic-1.0-Perl
- debian trixie: libstring-glob-permute-perl 0.01-4 Β· Artistic-1.0-Perl
- ubuntu noble: libstring-glob-permute-perl 0.01-4 Β· Artistic-1.0-Perl
- ubuntu resolute: libstring-glob-permute-perl 0.01-4 Β· Artistic-1.0-Perl
- ubuntu stonking: libstring-glob-permute-perl 0.01-4 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms