FileKGlob
view release on metacpan or search on metacpan
sub kglob {
my( @alts, @return, $user, $home );
foreach( @_ ) {
# If unquoted "{" in string, generate all possible combinations: #}
@alts= m#(^|[^\\])(\\\\)*\{# ? &unbrac( $_ ) : ( $_ ); #}
foreach( @alts ) {
if( m#^~([^/]+)# ) { # Expand ~user to user's home directory:
$user= $1 || getlogin(); # ~/ means "my" home directory
$home= $1 ? ( (getpwnam($1))[7] || "~$user" )
: ( (getpwuid($<))[7] || $ENV{'HOME'} || "/" );
s##$home#;
# Replace "~user" with user's home directory (unless no such
# user, then leave as is), unless is "~/" and getlogin()
# failed, then try by current UID then $HOME then "/".
}
if( m#(^|[^\\])(\\\\)*[\[\?\*]# ) { # Some kind of wildcard:
push( @return, &pglob($_) ); # Find matching files.
} else { # Just a string, perhaps with \-quoting:
s/\\(.)/\1/g; # Remove the \'s used for quoting.
push( @return, $_ );
( run in 0.240 second using v1.01-cache-2.11-cpan-8d75d55dd25 )