in reply to Re^2: Threading and File Handles
in thread Threading and File Handles

I'm not familiar enough with the "inner workings" of Perl to play around with "passing around control of filehandles". However, I rarely ever see this done, and to do it with threads adds another layer of complexity. I think you may be forging new territory/. :-)

My first thought is to forget about passing "filhandles" and to pass the "files saved in scalar variables" through the cond_broadcast facility in threads. I'm not too quick to whip off example code, but what I mean is to figure out how to pass scalars around between threads. Alot of examples have been posted how to do this. Then in each thread, use the "variable as a filehandle technique" like:

my $foo = ''; open FILEHANDLE, '+>', \$foo or die $!; print FILEHANDLE "Contents of File"; seek(FILEHANDLE,0,0); my @contents = <FILEHANDLE>; close FILEHANDLE or die $!; print 'From $foo: ', $foo, $/; print 'From file read: ', @contents, $/;
Now, in each thread, you can open and close on that variable, then "broadcast it" to the other threads where they can do the same thing.

I'm not really a human, but I play one on earth. flash japh