I have been looking through the code for this module to see if anything jumps out at me. Based on what you describe and the information in the linked trouble ticket, I wondered if there might be a race condition between the send and read subroutines.

So far I have identified only one unrelated bug in the Linux.pm code (I realize you are working with WinXP) but this prevented building the module on my linux box. Line 98 of Linux.pm should be:

$this->{START_CMD} = "$this->{R_BIN} --slave --vanilla" ;

The original included a "--gui=none" option that has been deprecated in the most recent versions of R>=2.1.

In any case, I will continue to plod through the send and read subroutines to see if I can find something useful. I will also post the code here with the hope that someone with a better endogenous perl parser can suggest a test or fix faster.

Here is the send subroutine from pipe.pm:

sub send { my $CLASS_HPLOO ; $CLASS_HPLOO = $this if defined $this ; my $this = UNIVERSAL::isa($_[0],'UNIVERSAL') ? shift : $CLASS_HPLO +O ; my $class = ref($this) || __PACKAGE__ ; $CLASS_HPLOO = undef ; my $cmd = shift(@_) ; $cmd =~ s/\r\n?/\n/gs ; $cmd .= "\n" if $cmd !~ /\n$/ ; $cmd =~ s/\n/\r\n/gs ; while ( $this->is_blocked ) { sleep(1) ;} my $n = $this->read_processR ; $n = 1 if $n eq '0' || $n eq '' ; my $file = "$this->{LOG_DIR}/input.$n.r" ; while( -e $file || -e "$file._" ) { ++$n ; $file = "$this->{LOG_DIR}/input.$n.r" ; } open (my $fh,">$file._") ; print $fh "$cmd\n" ; close ($fh) ; chmod(0777 , "$file._") ; $this->{OUTPUT_R_POS} = -s $this->{OUTPUT_R} ; rename("$file._" , $file) ; my $has_quit = 1 if $cmd =~ /^\s*(?:q|quit)\s*\(.*?\)\s*$/s ; ##print "CMD[$n]$has_quit>> $cmd\n" ; my $status = 1 ; my $delay = 0.02 ; my ($x,$xx) ; while( (!$has_quit || $this->{STOPING} == 1) && -e $file && $this- +>is_started( !$this->{STOPING} ) ) { ++$x ; ##print "sleep $file\n" ; select(undef,undef,undef,$delay) ; if ( $x == 20 ) { my (undef , $data) = $this->read_processR ; if ( $data =~ /\s$n\s+\.\.\.\s+\// ) { last ;} $x = 0 ; ++$xx ; $delay = 0.5 ; } if ( $xx > 5 ) { $status = undef ;} ## xx > 5 = x > 50 } if ( $has_quit && !$this->{STOPING} ) { $this->stop(1) ;} return $status ; }

and here is the read subroutine from pipe.pm.

sub read { my $CLASS_HPLOO ; $CLASS_HPLOO = $this if defined $this ; my $this = UNIVERSAL::isa($_[0],'UNIVERSAL') ? shift : $CLASS_HPLO +O ; my $class = ref($this) || __PACKAGE__ ; $CLASS_HPLOO = undef ; my $timeout = shift(@_) ; $timeout = -1 if $timeout eq '' ; open (my $fh, $this->{OUTPUT_R} ) ; binmode($fh) ; seek($fh , ($this->{OUTPUT_R_POS}||0) , 0) ; my $time = time ; my ($x,$data) ; while( $x == 0 || (time-$time) <= $timeout ) { ++$x ; my $s = -s $this->{OUTPUT_R} ; my $r = read($fh , $data , ($s - $this->{OUTPUT_R_POS}) , length +($data) ) ; $this->{OUTPUT_R_POS} = tell($fh) ; last if !$r ; } close($fh) ; my @lines = split(/(?:\r\n?|\n)/s , $data) ; return @lines if wantarray ; return join("\n", @lines) ; }

In reply to Re: Buggy CPAN Module (Statistics::R) by moklevat
in thread Buggy CPAN Module (Statistics::R) by maybeD

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.