home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
vile-src.zip
/
vile-8.1
/
perl
/
glob2re.pl
next >
Wrap
Perl Script
|
1998-04-04
|
711b
|
39 lines
#!/usr/bin/perl -w
sub glob2re {
my ($glob) = @_;
my $re = '(^|\/)';
while ($glob ne '') {
if ($glob =~ /^\*(.*)$/) {
$re .= '.*';
$glob = $1;
}
elsif ($glob =~ /^\?(.*)$/) {
$re .= '.';
$glob = $1;
}
elsif ($glob =~ /^\[(.+?)\](.*)$/) {
$re .= "[$1]";
$glob= $2;
}
elsif ($glob =~ /^\{(.*?,.*?)\}(.*)$/) {
my ($alts) = $1;
$glob = $2;
$re .= '(' . join('|',map(quotemeta,split(/,/, $alts))) . ')';
}
elsif ($glob =~ /^(.[^[{*?]*)(.*)$/) {
$re .= quotemeta($1);
$glob = $2;
}
else {
# shouldn't get here. If we do, give up
$glob = '';
}
}
$re .= '$';
return $re;
}
1;