눈바래다

#!/usr/bin/perl

 

use strict;

 

sub build_bigram {

 my ($word, $pre);

 my @words;

 my %bigram;

 

 while(<>){

  @words=split(/\s+/,$_);

  foreach $word (@words) {

   push(@{$bigram{$pre}}, $word);

   $pre=$word;

  }

 }

 #return @{$bigram{$pre}};

 return %bigram;

}

 

MAIN: {

 my %bigram;

 my @candidates;

 my ($pre, $choice, $i);

 

 %bigram=build_bigram();

 

 $pre="device";

 print "device ";

 

 for ($i=1; $i<100; $i++){

  @candidates=@{$bigram{$pre}};

  $choice=$candidates[int(rand($#candidates))];

  print $choice . " ";

  $pre=$choice;

 }

 

 print "\n";

}

 

 

[root@linuxtest kim]# ./ranvi.pl < messages

device strings: Mfr=1, Product=2, SerialNumber=0 Oct 7 10:32:41 linuxtest kernel: usb 7-1: new low speed USB OPTICAL MOUSE Oct 11 05:19:47 linuxtest kernel: usb 7-1: Manufacturer: PIXART Oct 6 22:43:33 linuxtest kernel: usb 7-1: New USB OPTICAL MOUSE as /devices/pci0000:00/0000:00:1d.1/usb7/7-1/7-1:1.0/input/input2999 Oct 6 07:34:48 linuxtest kernel: generic-usb 0003:093A:2510.06CE: input,hidraw2: USB device found, idVendor=093a, idProduct=2510 Oct 11 08:53:51 linuxtest kernel: generic-usb 0003:093A:2510.413B: input,hidraw2: USB device number 12 using uhci_hcd Oct 9 05:23:16 linuxtest kernel: usb 7-1: USB OPTICAL MOUSE] on usb-0000:00:1d.1-1/input0 Oct 6 15:17:57 linuxtest kernel: usb 7-1: configuration #1 chosen from 1 choice Oct 8 02:16:09 linuxtest kernel: usb 7-1: New

[root@linuxtest kim]#