Greetings Fellow Monks:
I am in serious need of your wisdom and help.
The goal is to list the contents of a directory (no problem)
and do something with the files that contain,match via grep
to specific patterns; one that will always be at the start of the file, and the other somewhere in the middle of the filename. In other words I want to match a file, for example, that has to contain STR1 at the beginning, and _STR2_ (the underscores are required), somewhere in the middle.
With the correct regex:
STR1some_STR2_file.txt would match
.whereas.
STR1some_STR2file.txt would NOT match
with the code below I have managed to get the qualifier for the beginning of the string to be matched, however to have both matches I have no clue.
#!/usr/bin/perl -w
use strict;
use FileHandle;
my $localdir="C:\\PROJECTS\\";
my $id="LWX1";
opendir LOCALDIR, "$localdir";
my @local_files = grep /^$id/i, readdir LOCALDIR;
###my guess fr both would be this: (doesn't work)
###where "_arbv_" is the 2nd string that must be matched
#my @local_files = grep /^$id&&_arbv_/i, readdir LOCALDIR;
closedir LOCALDIR;
##determine which files to download
foreach my $local (@local_files)
{
print "$local\n";
}
Your help in this matter is greatly appreciated. For I am stumped with this one! Thanks in advance.
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.