text::glob(3) [osx man page]
Text::Glob(3) User Contributed Perl Documentation Text::Glob(3) NAME
Text::Glob - match globbing patterns against text SYNOPSIS
use Text::Glob qw( match_glob glob_to_regex ); print "matched " if match_glob( "foo.*", "foo.bar" ); # prints foo.bar and foo.baz my $regex = glob_to_regex( "foo.*" ); for ( qw( foo.bar foo.baz foo bar ) ) { print "matched: $_ " if /$regex/; } DESCRIPTION
Text::Glob implements glob(3) style matching that can be used to match against text, rather than fetching names from a filesystem. If you want to do full file globbing use the File::Glob module instead. Routines match_glob( $glob, @things_to_test ) Returns the list of things which match the glob from the source list. glob_to_regex( $glob ) Returns a compiled regex which is the equivalent of the globbing pattern. glob_to_regex_string( $glob ) Returns a regex string which is the equivalent of the globbing pattern. SYNTAX
The following metacharacters and rules are respected. "*" - match zero or more characters "a*" matches "a", "aa", "aaaa" and many many more. "?" - match exactly one character "a?" matches "aa", but not "a", or "aaa" Character sets/ranges "example.[ch]" matches "example.c" and "example.h" "demo.[a-c]" matches "demo.a", "demo.b", and "demo.c" alternation "example.{foo,bar,baz}" matches "example.foo", "example.bar", and "example.baz" leading . must be explictly matched "*.foo" does not match ".bar.foo". For this you must either specify the leading . in the glob pattern (".*.foo"), or set $Text::Glob::strict_leading_dot to a false value while compiling the regex. "*" and "?" do not match / "*.foo" does not match "bar/baz.foo". For this you must either explicitly match the / in the glob ("*/*.foo"), or set $Text::Glob::strict_wildcard_slash to a false value with compiling the regex. BUGS
The code uses qr// to produce compiled regexes, therefore this module requires perl version 5.005_03 or newer. AUTHOR
Richard Clamp <richardc@unixbeard.net> COPYRIGHT
Copyright (C) 2002, 2003, 2006, 2007 Richard Clamp. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
File::Glob, glob(3) perl v5.16.2 2013-08-25 Text::Glob(3)
Check Out this Related Man Page
Permute(3pm) User Contributed Perl Documentation Permute(3pm) NAME
String::Glob::Permute - Expand {foo,bar,baz}[2-4] style string globs 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 "; } # hostfoo2 # hostbar2 # hostbaz2 # hostfoo3 # hostbar3 # hostbaz3 # hostfoo4 # hostbar4 # hostbaz4 DESCRIPTION
The "string_glob_permute()" function provided by this module expands glob-like notations in text strings and returns all possible permutations. For example, to run a script on hosts host1, host2, and host3, you might write @hosts = string_glob_permute( "host[1-3]" ); and get a list of hosts back: ("host1", "host2", "host3"). Ranges with gaps are also supported, just separate the blocks by commas: @hosts = string_glob_permute( "host[1-3,5,9]" ); will return ("host1", "host2", "host3", "host5", "host9"). And, finally, using curly brackets and comma-separated lists of strings, as in @hosts = string_glob_permute( "host{dev,stag,prod}" ); you'll get permutations with each of the alternatives back: ("hostdev", "hoststag", "hostprod") back. 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"). The patterns allow numerical ranges only [1-3], no string ranges like [a-z]. Pattern must not contain blanks. 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. 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. If you want ("host08", "host09", "host10"), instead, pad all integers in the range expression accordingly: @hosts = string_glob_permute( "host[08-09,10]" ); # ("host08", "host09", "host10") Note on Perl's internal Glob Permutations Note that there's a little-known feature within Perl itself that does something similar, for example print "$_ " for < foo{bar,baz} >; will print foobar foobaz if there is no file in the current directory that matches that pattern. String::Glob::Permute, on the other hand, expands irrespective of matching files, by simply always returning all possible permutations. It's also worth noting that Perl's internal Glob Permutation does not support String::Glob::Permute's [m,n] or [m-n] syntax. 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> perl v5.12.4 2009-01-29 Permute(3pm)