Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: create search string from array elements

by friedo (Prior)
on Jul 12, 2005 at 13:19 UTC ( [id://474270]=note: print w/replies, xml ) Need Help??


in reply to create search string from array elements

If you want to be clever you could make an alternating pattern from the list of dates:

my $pat = join '|', @dates; my @files = grep /$pat/, @logfiles;

But I have no idea if that would be faster or slower than just doing a nested loop. A nested loop at least gives you the option of skipping the remainder when you've found a match.

my @files; foreach my $file( @logfiles ) { foreach my $date( @dates ) { if ( $file =~ /$date/ ) { push @files, $file; last; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found