Create a gist now

Instantly share code, notes, and snippets.

@moccos /find.pl
Last active Mar 18, 2017

[Perl] GNU find wrapper to set -regextype.
#!/usr/bin/perl
use strict;
my $idx = 0;
my @preopt = ("-H", "-L", "-P");
my $command = "find";
my $regex_type = " -regextype posix-egrep";
# check @preopt
for (; $idx <= $#ARGV; $idx++) {
my $matched = 0;
foreach(@preopt) {
if ($_ eq $ARGV[$idx]) {
$matched++;
last;
}
}
last if ($matched == 0);
$command .= " " . $ARGV[$idx];
}
# check path
if (substr($ARGV[$idx], 0, 1) ne "-") {
$command .= " " . $ARGV[$idx];
$idx++;
}
# concatenate regextype option and remaining
$command .= $regex_type;
for (; $idx <= $#ARGV; $idx++) {
if (substr($ARGV[$idx], 0, 1) ne "-") {
$command .= " '$ARGV[$idx]'";
} else {
$command .= " $ARGV[$idx]";
}
}
system($command);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment