in reply to Re^3: Count byte/character occurrence (quickly)
in thread Count byte/character occurrence (quickly)

Just noticed that you were the author of that module haha. anyways, I have read a file into a buffer and then opened it like:
my $arg = shift; my $len = -s $arg; open my $file, '<', $arg; binmode $file; read $file, my $buf, $len; close $file; open my $mem_file, '<', \$buf; binmode $mem_file; .....do stuff....
when I try to use mce_open with $mem_file, I get an error:
open error: Invalid argument at C:/Perl/site/lib/MCE/Shared/Server.pm +line 1035 thread 1, <__ANONIO__> line 6. MCE::Shared::Server::__ANON__() called at C:/Perl/site/lib/MCE +/Shared/Server.pm line 1324 thread 1 MCE::Shared::Server::_loop(0, 6624) called at C:/Perl/site/lib +/MCE/Shared/Server.pm line 335 thread 1 eval {...} called at C:/Perl/site/lib/MCE/Shared/Server.pm lin +e 335 thread 1

Is there anyway I can get this to work? Because I have passed around this $mem_file in my script and would like to use it instead of having to re-read the actual file. If i need to elaborate any more please let me know :)

EDIT: I will go ahead and elaborate a little more. when I pass $mem_file to the sub and try to open it like this:

stat_check($mem_file); sub stat_check{ my ($mem_file) = @_; my $fh = MCE::Shared->handle( "<:raw", \$mem_file ); ....rest of threaded function... }

I get error:

Not a GLOB reference at C:/Perl/site/lib/MCE/Shared/Server.pm line 203 +6, <__ANONIO__> line 3.

If i try:

stat_check($mem_file); sub stat_check{ my ($mem_file) = @_; my $fh = MCE::Shared->handle( "<:raw", $mem_file ); ....rest of threaded function... }

I get error:

open error: Invalid argument at C:/Perl/site/lib/MCE/Shared/Server.pm +line 1035 thread 1, <__ANONIO__> line 6. MCE::Shared::Server::__ANON__() called at C:/Perl/site/lib/MCE +/Shared/Server.pm line 1324 thread 1 MCE::Shared::Server::_loop(0, 3232) called at C:/Perl/site/lib +/MCE/Shared/Server.pm line 335 thread 1 eval {...} called at C:/Perl/site/lib/MCE/Shared/Server.pm lin +e 335 thread 1

Replies are listed 'Best First'.
Re^5: Count byte/character occurrence (quickly)
by marioroy (Prior) on Apr 05, 2016 at 07:57 UTC

    Unfortunately, MCE::Shared does not support a handle obtained by opening a scalar reference. Shared file handles have a real file descriptor.

      Ok, I was just wondering, because the file has already been read once and seems like it would be even faster if it could act on the scalar. Thanks anyway :)