If i guessed your specs right you are after an intersection.

Hence something like this using Set::Scalar and Path::Tiny might be a way to go:

#!/usr/bin/env perl use strict; use warnings; use Set::Scalar; use Path::Tiny; use Data::Dump; use feature qw (say); say path("file01.txt")->slurp_utf8; say path("file02.txt")->slurp_utf8; my @s = path("file01.txt")->lines_utf8( { chomp => 1 } ); my @t = path("file02.txt")->lines_utf8( { chomp => 1 } ); dd \@s; dd \@t; my $s = Set::Scalar->new(@s); my $t = Set::Scalar->new(@t); my $i = $s->intersection($t); say $i; path("out.txt")->spew_utf8( map { "$_\n" } @$i ); print path("out.txt")->slurp_utf8; __END__ karls-mac-mini:sabas karl$ ./sabas.pl foo bar donald nose cuke donald ["foo", "bar", "donald"] ["nose", "cuke", "donald"] (donald) donald

OK, admittedly very simplified. And 300K isn't really large IMHO. Threads From Hell #2: How To Search A Very Huge File [SOLVED] might probably also be of interest. If you want to get rid of this @ARGV stuff see Re: GetOpt Organization. Some might say that i repeat myself ;-)

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help


In reply to Re: searching in large file by karlgoethebier
in thread searching in large file by sabas

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.