Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: FileHandles and threads

by Anonymous Monk
on Apr 20, 2013 at 18:12 UTC ( #1029672=note: print w/replies, xml ) Need Help??

in reply to FileHandles and threads


i have used the code and comment, because my problem was a little similar. i need to access to a big file (6Go / 12M protein records) to search for fuzzy similary

so i give my solution, it's a good start and maybe it will be useful to someone



#! perl -slw use strict; use warnings; use threads; use Thread::Queue; my $file="/path_to_the_file" ; our $file_handler ; our $ref_file_handler ; my ( $process_1 , $process_2 , $process_3 ) ; my $flag_on_file = Thread::Queue->new ; # main open $file_handler, '<', $file or warn "$file : $!" and die; $flag_on_file->enqueue(fileno($file_handler)); # threads creation $process_1 = threads->new( \&my_sub ); $process_2 = threads->new( \&my_sub ); $process_3 = threads->new( \&my_sub ); # waiting for all threads to stop before exit $process_1->join; $process_2->join; $process_3->join; # end main # sub sub my_sub { my( $fileno ) = $flag_on_file->dequeue ; open $ref_file_handler, "<&=$fileno" or warn $! and die; for ( 1..10 ) { # do something with the file # exemple print threads->self->tid.": ".scalar <$ref_file_handler> ; } close $ref_file_handler; $flag_on_file->enqueue(fileno($file_handler)); # do something with data } exit;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029672]
[thao4]: I posted my question, Could you help me , Please ?
[thao4]: posted with the title :Replace a patern_2 in 30 lines from the line with the patern_1 founded
[Eily]: karlgoethebier but we're trying to stay hidden!
[shmem]: thao4 example of the text and program missing in your post
[Eily]: also you can use <p> or <br /> tags to have multiple lines
[hippo]: Please also take a moment to read through I know what I mean. Why don't you? - this guidance will help others to help you.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-02-21 10:13 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (277 votes). Check out past polls.