in reply to Re^3: How to split file for threading?
in thread How to split file for threading?

Thank you very much. I like to learn by example and this is great. I'll be honest I'm trying to understand how the code works as I am still very novice to Perl and programming in general. what do these lines mean?   1+index( <$fh>, $target ) and ++$count while tell( $fh ) < $end; Is this reading the file line by line, returning line number where $target is found, and increasing $count for every time $target is found? Tell function returns the index position just to check end of file? Why couldn't you do while (<$fh>)?
our $T //= 4;
I couldn't really google two forward slashes so I don't know what this means.
my @threads = map{ threads->new( \&worker, $filename, $target, $chunks[ $_ ], $chunks +[ $_+1 ] ) } 0 .. $T-1;
Ok map will transform arrays, but here it seems like it is assigning 3 threads to @threads? threads->new() creates new thread while passing the worker sub and 4 variables? or is it creating a worker sub and passing those variables to worker?
my $total = 0; $total += $_->join for @threads;
this concatenates the thread results? but i don't see where or when the lines with $target were passed back and stored? Thanks again

Replies are listed 'Best First'.
Re^5: How to split file for threading?
by BrowserUk (Patriarch) on Jun 23, 2015 at 19:14 UTC

    Sorry, but I don't think you are ready to do multitasking yet.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
      Speaking of judgement ... when do you retire?