I think halley has it right with building an index using an MD5 checksum of your paragraphs is the way to go.

I though it worth mentioning that you can easily read a file, paragraph by paragraph by setting local $/ = '';

The following script builds an in memory index (filename/byte offset) for every file in a list given on the command line.

It indexed every paragraph in 512 html files in my perl distribution in under 10 seconds and 6MB.

#! perl -slw use strict; use G; ## Expands command line wildcards use Data::Dumper; use Digest::MD5 qw[ md5_hex ]; local $/ = ''; ## paragraph mode. my( $pos, %index ) = 0; ## The first para start at offset 0 while( <> ) { ## build a HoAoAs, MD5 is the key ## The values are arrays of [ filename, offset ]. push @{ $index{ md5_hex( $_ ) } }, [ $ARGV, $pos ]; ## Getthe next offset $pos = tell ARGV; ## Back to 0 if we reached the EOF $pos = 0 if eof( ARGV ); } print Dumper \%index; __END__ C:\Perl\html>p:359522 *.html *\*.html *\*\*.html Processed 512 files and 5829 paragraphs into 3293 unique signatures.

By storing the offset, you can seek to the place n the file(s) that have a matching MD5 and verify that the paras are indeed identical. There is a small, but statistically possible chance of collisions.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

In reply to Re: Efficiency: Finding if a file contains a paragraph by BrowserUk
in thread Efficiency: Finding if a file contains a paragraph by C_T

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.