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);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.