begin quoting SJS as of Thu, Feb 21, 2008 at 04:14:30PM -0800: [snip] > Do you run your sigs thru strfile first? > > Hm... I can't find the randstr example on my system, despite the > manpages claiming that it's part of this distribution. Nor do I have > the strfile.h header, contrary to what I would expect.
Ah, "apt-get source fortunes" took care of that. > [snip] > > For this sort of text processing, I'd probably reach for perl before > trying to build something out of grep. Hm. Someone has built strfile in perl already: http://www.kluge.net/~felicity/ppt/strfile And then there's a module to directly ready strfile databases http://dir.filewatcher.com/d/Debian/ia64/libs/libfortune-perl_0.2-1_ia64.deb.12302.html Looking at the synopsis, I see a useful fragment: # input $ffile = new Fortune ($base_filename); $ffile->read_header (); $num_fortunes = $ffile->num_fortunes (); $fortune = $ffile->read_fortune ($num); $fortune = $ffile->get_random_fortune (); In just a few minutes (mostly looking up perl syntax), I arrive at: ----------------------------------------------------------------------------- #!/usr/bin/perl # # Stupid little test script to play with libfortune-perl use Fortune; $pat = @ARGV[0]; $ffile = new Fortune( "/usr/share/games/fortunes/fortunes" ); #$ffile = new Fortune( "/usr/share/games/fortunes/riddles" ); $ffile->read_header(); $num_fortunes = $ffile->num_fortunes(); for ($count = 0; $count < $num_fortunes; $count++ ) { $body = $ffile->read_fortune( $count ); if ( $body =~ /$pat/ ) { push( @hits, $body ); } } print @hits[ rand scalar( @hits ) ]; ----------------------------------------------------------------------------- (No error checking, and really inefficient, and insufficiently flexible, but it seems to do the right thing. Adapt as needed.) -- Perl - the glue programming language, Oh-so-sticky, and so much fun as well! Stewart Stremler -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
