Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Searching for files efficiently help!

by Anonymous Monk
on Nov 16, 2011 at 19:02 UTC ( [id://938439]=note: print w/replies, xml ) Need Help??


in reply to Re: Searching for files efficiently help!
in thread Searching for files efficiently help!

I have a question for you, if the values in this array @filelist was like this:my @filelist = qw(88732 99877 76211); I would have to match if these values are part of these file names in array @files, how would the regular expression be in this case. In another words matching values from @filelist against values in in the array @files that would be like this: my @files = qw(99877_bc_20101000.txt 99877_xy_20111111.txt 76211_bc_20101000.txt);
I hope I was clear on that. Thanks!

Replies are listed 'Best First'.
Re^3: Searching for files efficiently help!
by hbm (Hermit) on Nov 16, 2011 at 19:45 UTC

    If I understand, you can simply narrow your regex to match up to the first underscore, and see if that 'exists':

    foreach my $files(@files) { $c++; if($files=~m|.*/([^_]+)|) { $f_name = $1; } if (exists $filelist{$f_name}) { print "$c - Found and to be deleted: $files\n"; } }

    I might go as far as:

    for (@files) { $c++; if(m|.*/([^_]+)| && exists $filelist{$1} ) { print "$c - Found and to be deleted: $_\n"; } }
      I like this, thanks very much!
Re^3: Searching for files efficiently help!
by Anonymous Monk on Nov 16, 2011 at 19:24 UTC
    In this case I would put back the second foreach loop:
    foreach my $chk_file(@filelist) { #if($chk_file=~/$f_name/) { if($f_name=~/$chk_file/) { print "$c - Found and to be deleted: $files\n"; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found