In case anybody cares, I finally got it to do what I was trying to do. If anybody needs to parse large text files using multi-threading, here's a simple script that might help. I apologize about my original post's vagueness. I have never posted on here before and had forgotten about the tags that you can use. Anyway, If people can improve upon it, feel free. I'm always looking for better ways to do things.
use strict; use warnings; use threads; use threads::shared; use Thread::Queue; # Constant that hold maximum amount of threads to start use constant MAX_THREADS => 10; # Main data structure that holds all the data my %hash : shared; # A new empty queue my $q = Thread::Queue->new(); # Build list of files my @files = qw/<file1> <file2> <file3> <etc.>/; chomp(@files); # Enqueue the files $q->enqueue(map($_, @files)); # Start the threads and wait for them to finish for(my $i=0; $i<MAX_THREADS; $i++) { threads->create( \&thread, $q )->join; } # Print out the data structure when we're finished foreach my $key1 (keys %hash) { print "$key1 =>\n"; foreach my $key2 (keys %{$hash{$key1}}) { print "\t$key2 =>\n"; print map("\t\t$_\n", @{$hash{$key1}{$key2}}); } } ############################# # This code runs inside of the thread ############################# sub thread { my ($q) = @_; while (my $file = $q->dequeue_nb()) { my @array1 : shared; my @array2 : shared; my @array3 : shared; # Lock the main hash before writing lock(%hash); chomp($file); # Initialize has with the file/key $hash{$file} = &share({}); # Open the file and pattern match the lines open(FH, $file) or die "Can't open\n"; while(my $line = <FH>) { chomp($line); # Build arrays of the things we're # looking for in the file(s) if($line =~ /^<regex1>/) { push(@array1, $line); } elsif($line =~ /^<regex2>/) { push(@array2, $line); } elsif($line =~ /^<regex3>/) { push(@array3, $line); } } close(FH); share ( $hash{$file}{<type1>} ); share ( $hash{$file}{<type2>} ); share ( $hash{$file}{<type3>} ); # Can only assign arrays as a reference $hash{$file}{<type1>} = \@array1; $hash{$file}{<type2>} = \@array2; $hash{$file}{<type3>} = \@array3; } } exit;

In reply to Re^3: Sharing Hash Question by jmmach80
in thread Sharing Hash Question by jmmach80

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.