anyway, the problem is it is segfaulting somewhere in highligh_block. A malloc is blowing up while trying to enlarge a SV. I'd appreciate anyone else letting me know if this happens to them too.
Fire it up with perl "thing" "book.txt" where thing is the word you want to search the book.txt for. In desperation, use a manpage. It will find any occurences of "thing" separated by a number of letters. e.g.
---This is the original text---------------------------------------- s face went white. It just wasnt all sunshine, he whispered, shaking his head. Not all sunshine, thats all Im saying. What does he mean? said Gurder, brightly. He d ---Secret spooky message in text is in capitals--------------------- s f a c e w e n t w h i t e i t j u s T w a s n t a l l s u n s h i n e . H e w h i s p e r e d s h a k i n g h I s h e a d n o t a l l s u n s h i N e t h a t s a l l i m s a y i n G w h a t d o e s h e m e a n s a i d g u r d e r b r i g h t l y h e d
here's the code:
#!/usr/bin/perl use strict; use warnings; #use diagnostics; my $letter_separation = 80; my $word = shift @ARGV; my $file = shift @ARGV; my $text; #Read in the contents of the file open FH, "<$file" or die "couldn't open $file for input"; { local $/; $text = <FH>; } close FH; my $origtext = $text; my @words = split /[[:space:][:punct:]]/, $text; my @wordlist = grep {length $_ > 3} @words; {local $, = "!"; #print "\nCompiled this wordlist:", @wordlist,"\n"; } my %words; $words{$_}=1 foreach @wordlist; @wordlist = keys %words; $text =~ s/\n|\r/ /g; $text =~ s/[[:punct:][:space:]]//g; $text = lc($text); foreach my $sep ( 1..$letter_separation) { print "Searching for words with a letter separation of $sep\n"; my @letters = split //, $word; my @regexp = ("(.{0,20}", join(".{$sep}", @letters), ".{0,".($sep+20) +."})"); my $regexp = join "", @regexp; #print $regexp, "\n\n"; while ( $text =~/$regexp/ig ) { my $block = highlight_block ( $1, $sep, $word ); foreach my $s ( 1..$sep) { my $i; my $charlength; foreach ( @wordlist ) { print "Word number: ", $i++, "\n"; $charlength += length($_); print "Total length sent: $charlength\n"; $block = highlight_block ( $block, $s, $_ ) ; } } print "---This is the original text--------------------------------- +-------\n"; print find_orig($origtext, $block), "\n"; print "---Secret spooky message in text is in capitals-------------- +-------\n\n"; print format_block($block, $sep), "\n"; } } sub format_block { my ( $block, $sep) = @_; return $block if $sep < 10; my $regexp = "(.{".($sep+1)."})"; $block =~ s/$regexp/$1\n/ig; $block =~ s/(.)/$1 /g; return $block; } sub highlight_block { my ($block, $sep, $word)=@_; #print "Before $word, $sep\n"; my @let = split //, $word; my $rep = ''; my $i=1; foreach my $l (@let) {$l = "(".$l.")(.{$sep})"; $rep.='\u$'.$i++.'$ +'.$i++.'';}; my $regexp2 = join "", @let; #print "Now scanning substring with $regexp2 and replacement target +$rep\n"; my $ev = '$block =~ '."s/$regexp2/$rep/i"; eval $ev; print $block, "\n\n"; #print "block after\n"; return $block; } sub find_orig { my ($orig, $block)=@_; my @search = split //, $block; my $search = join("","(", join( "[[:space:][:punct:]]*", @search), ") +"); $orig =~ /$search/gi; return $1;
and the backtrace looks like this:
(gdb) bt #0 0x400b9fe9 in malloc () from /lib/libc.so.6 #1 0x400b9e44 in malloc () from /lib/libc.so.6 #2 0x808b7cb in Perl_safemalloc () #3 0x809e77a in Perl_sv_grow () #4 0x80a1d66 in Perl_newSV () #5 0x80b35b5 in Perl_pp_split () #6 0x80972c0 in Perl_runops_standard () #7 0x805c795 in perl_run () #8 0x805c4fb in perl_run () #9 0x8059ed0 in main () #10 0x4006564f in __libc_start_main () from /lib/libc.so.6}
____________________
Jeremy
I didn't believe in evil until I dated it.
In reply to Segfault on extending SV (malloc) by jepri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |