ll001 has asked for the wisdom of the Perl Monks concerning the following question:
Happy Friday Monks! I was wondering how I would pass a regex like this:
(/opt/backups/maindb[0-9]+.db/table[0-9]+.tn/chunk[0-9]+.cn/)
as an argument to a subroutine which executes a command on the (one and only) path matching that regex? Sample below hopefully illustrates what I'm trying to do.
#!/usr/bin/perl -w use strict; my $regexStr = qr{[0-9]+}; my $suff = ".dn"; listThisFolder($regexStr); sub listThisFolder { my ($regexStr) = @_; my $getDir = ("c:\\sh\\"); # I know that the folder exists, but I don't know what the table # suffix or chunk suffix would be (table-129.tn or table-001.t +n, etc). # $ls would hold the contents of the folder which expanded from th +e regex my $ls = `dir $getDir$regexStr$suff`; print "$ls\n"; #return($ls); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing regex to a subroutine
by aitap (Curate) on Oct 12, 2012 at 19:33 UTC | |
by ll001 (Initiate) on Oct 12, 2012 at 19:47 UTC | |
by mbethke (Hermit) on Oct 12, 2012 at 21:26 UTC | |
|
Re: Passing regex to a subroutine
by Lotus1 (Vicar) on Oct 12, 2012 at 23:13 UTC | |
|
Re: Passing regex to a subroutine
by AnomalousMonk (Archbishop) on Oct 13, 2012 at 10:33 UTC | |
|
Re: Passing regex to a subroutine
by kcott (Archbishop) on Oct 13, 2012 at 10:43 UTC |