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); }

In reply to matching regex on an array element w/o looping the array by gnu@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.