Sorry about the vagueness, but I've written a script which is throwing
phase-of-moon SEGVs at me. The only thing that seems to be in common is
that I'm using an arithmetical for (C-style for) and manipulating $_
within it. Linux and perl 5.001l.
Sorry I can't quote a reproducible example, but the problem comes and
goes with trivial changes - e.g. adding print statements, running on
different machine etc.. Can anyone shed any light?
This routine here (sometimes) threw a SEGV at me while $source was
just the global $_ rather than a parameter. It would go 3500 times
round the loop, then crash 311 iterations in on the second call.
sub addcounts { # size, threshold
my ( $size, $threshold, $source ) = @_;
print STDERR "size=$size threshold=$threshold\n";
my %count = ();
my $end = length($source) - $size ;
warn "end=$end size=$size length=",length($source),"\n";
for($i=0; $i<$end ; $i++) {
my $str = substr($_,$i,$size); # <<<SEGV HERE
##fix using this my $str = substr($source,$i,$size);
$count{$str}++ unless $str =~ /[\0\n]/ };
while(($k,$v)=each %count) {
push @counts,[$k,$v*(length($k)-1)] if $v>=$threshold;
};
print STDERR ": ", +(scalar keys %count)," words, ",
(scalar @counts)," over threshold\n";
}
having decided that this was too vague to report, I now run into another
one. I'm counting the occurrence of REs in a string, and this statement,
later in the program, is SEGVing:
for $ch (@counts[0.. ($#counts>10 ? 10 : $#counts )]) {
$ch->[1] = ( s/\Q$ch->[0]/$ch->[0]/g ) * (length($ch->[0]) - 1 );
This loop is within another arithmetical "for": for($slot=255; $slot>0; $slot--)
I feel sure there must be a better way of counting REs in a string. I
don't want to pull all the matches into a vector, since this could be
too large for comfort when I run this for real.
Thank you for reading this far :-)
Ian
phase-of-moon SEGVs at me. The only thing that seems to be in common is
that I'm using an arithmetical for (C-style for) and manipulating $_
within it. Linux and perl 5.001l.
Sorry I can't quote a reproducible example, but the problem comes and
goes with trivial changes - e.g. adding print statements, running on
different machine etc.. Can anyone shed any light?
This routine here (sometimes) threw a SEGV at me while $source was
just the global $_ rather than a parameter. It would go 3500 times
round the loop, then crash 311 iterations in on the second call.
sub addcounts { # size, threshold
my ( $size, $threshold, $source ) = @_;
print STDERR "size=$size threshold=$threshold\n";
my %count = ();
my $end = length($source) - $size ;
warn "end=$end size=$size length=",length($source),"\n";
for($i=0; $i<$end ; $i++) {
my $str = substr($_,$i,$size); # <<<SEGV HERE
##fix using this my $str = substr($source,$i,$size);
$count{$str}++ unless $str =~ /[\0\n]/ };
while(($k,$v)=each %count) {
push @counts,[$k,$v*(length($k)-1)] if $v>=$threshold;
};
print STDERR ": ", +(scalar keys %count)," words, ",
(scalar @counts)," over threshold\n";
}
having decided that this was too vague to report, I now run into another
one. I'm counting the occurrence of REs in a string, and this statement,
later in the program, is SEGVing:
for $ch (@counts[0.. ($#counts>10 ? 10 : $#counts )]) {
$ch->[1] = ( s/\Q$ch->[0]/$ch->[0]/g ) * (length($ch->[0]) - 1 );
This loop is within another arithmetical "for": for($slot=255; $slot>0; $slot--)
I feel sure there must be a better way of counting REs in a string. I
don't want to pull all the matches into a vector, since this could be
too large for comfort when I run this for real.
Thank you for reading this far :-)
Ian