Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi Monks!
I having an issue where I am trying to search in this directory structure for all html files that will match against a list of file names in an array(@filelist). I am finding all the HTMLs fine using "File::Find::Rule" searching recursively, but my issue is finding the best way to get only the file names that match in the @filelist array into the @found_html array in my code. Literally using the names in the @filelist array to search for them in the directory($dir) and place the found file names in the @found_html.

Thanks for looking!!!
#!/usr/bin/perl -w use strict; use File::Find::Rule; use File::Basename; my @filelist = qw(1234567_3a_20101000.html 99877_b_20111111.html 9987 +7_c_20111111.html 99877_d_20111111.html 99877_e_20111111.html 99877_u +f_20111111.html 1234567_g_20101000.html 99877_h_20111111.html 99877 +_i_20111111.html 99877_j_20111111.html 99877_k_20111111.html 99877_ll +_20111111.html 1234567_pl_20101000.html 99877_qa_20111111.html 998 +77_rr_20111111.html 99877_sx_20111111.html 99877_xy_20111111.html 998 +77_nm_20111111.html); my $dir = '/var/www/files/'; my $find = File::Find::Rule ->file ->name(qr/\.html?$/) ->start( $dir ); my $f_count = 0; my @found_html; while ( defined ( my $html_document = $find->match ) ) { $f_count++; my $filenames = basename( $html_document ); foreach my $chk_file(@filelist) { if($chk_file=~/$filenames/g) { push @found_html, $filenames; } } }

In reply to Search array of file names in directory structure by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found