I use this script when I recursively (i.e., with wget(1)) web-suck a site and have hundreds (sometimes thousands, as in the case of rfc's or recipes or such things) of files named things like "1001.html" "1002.html" and so on. This little snippet takes every file in the current directory and writes it to a hash as a scalar. You can then take this hash and run searches on it (such as in the case of RFC's or looking for a recipe that contains tuna, mustard, and noodles). Useful, tiny, and even better, it works!

Your files are written to a file called 'brick'. Move that to wherever you're working on your neato searching script.

note: the warnings pragma is a 5.6ism.

#!/usr/bin/perl use warnings; use strict; use Carp; use Storable qw{ freeze }; use File::Slurp; my %html_files; opendir TD, '.' or croak $!; foreach my $file (readdir TD) { $html_files{$file} = read_file($file); } my $brick = freeze( \%html_files ); open OUT, ">brick" or croak $!; print OUT $brick; close OUT or carp $!; exit 0; # 'good' exit for the shell

In reply to All files in dir to Storable.pm data by deprecated

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.