In the follow code (in progress), I have two arrays, @toget and @sourcefiles. @toget contains a list of base file names I need to find (they might have a different extension) and @sourcefiles is a listing of all the files I wish to look through.
What I am wondering is if I can match a regex against an array to see if there is an element that matches, if so, I want to retrieve that element.
For example, can I do this: if (@sourcefiles =~ /.*P.*\.0912\.ama\.gz/) { ..code.. };
I am trying to avoid having to do a File::Find on every pattern I'm looking for or having to iterate through the arrays to compare @toget to see if each element is in @sourcefiles.
Any ideas are appreciated.
TIA, Chad.
#!/usr/local/bin/perl -w
use strict;
use File::Find;
use Data::Dumper;
my $file = "/u90/gvc_archive/ama_recover/chad.lst";
my $startDir = "u90/gvc_archive/ama_recover";
my $destDir = "$startDir/4tych";
my @toget;
my @sourcefiles;
chdir $startDir;
open(FILES,"<$file");
for (<FILES>){
push(@toget,$_);
}
find(\&pushsources,".");
sub pushsources {
my $file = $File::Find::name;
push(@sourcefiles,$file);
}
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.