gnu@perl has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: matching regex on an array element w/o looping the array
by sauoq (Abbot) on Oct 03, 2002 at 15:11 UTC | |
|
Re: matching regex on an array element w/o looping the array
by antifun (Sexton) on Oct 03, 2002 at 15:32 UTC | |
|
Re: matching regex on an array element w/o looping the array
by helgi (Hermit) on Oct 03, 2002 at 16:27 UTC | |
by gnu@perl (Pilgrim) on Oct 03, 2002 at 18:50 UTC | |
by gnu@perl (Pilgrim) on Oct 03, 2002 at 17:56 UTC | |
by helgi (Hermit) on Oct 04, 2002 at 13:35 UTC | |
by gnu@perl (Pilgrim) on Oct 04, 2002 at 19:33 UTC |