#!/usr/local/bin/perl # $Id:$ # lottery.pl - check numbers for lottery postcards # # [usage] # lottery.pl [-s sourcefile] [hitfile] # # sourcefile: File including numbers in all cards. # The default is ./source.txt # hitfile : File including hit numbers.. # The default is ./hit.txt # # [description of hitfile] # :number [number ...] # Comments start with '#'. # example: # 1:123456 # 2:12345 # 3:4321 7654 # Furusato Kozutsumi # # [description of sourcefile] # [#] # Comments start with '#'. # example: # 987654 # Larry Wall # 654321 # Donald E. Knuth $ver = "0.1"; if ( $ARGV[0] =~ /^-[^s]$/ ) { die "Usage: lottery.pl [-s /path/to/source.txt] /path/to/hit.txt\n"; } print "lottery.pl version $ver\n"; print "Copyright (C) 2005, nao \n"; if ( $ARGV[0] eq "-s" ) { shift( @ARGV ); $source = $ARGV[0]; shift( @ARGV ); } else { $source = "./source.txt"; } if ( $ARGV[0] eq "" ){ $hit = "./hit.txt" ; } else { $hit = $ARGV[0]; } @s = ""; @nums = ""; $total = 0; open(S, "<$source") || die "Error: cannot open $source\n"; while( ){ if ( /^\d/ ){ push( @s, $_ ); } } close(S); open(H, "<$hit") || die "Cannot open $hit\n"; while( ){ if ( /^$/ ){ next; } parse(); print("\n>>>$order-tou: @nums\n"); for( $i = 0; $i < @nums; $i++ ) { $num = @nums[$i]; foreach $line ( @s ){ if ( $line =~ /^(\d*)($num)([\s\t\n\#]+.*)$/ ){ my $tmp = $3; chomp($tmp); print("$1\[$num\]$tmp\n"); $total++; } } } } close(H); $all = @s; print "\n$total/$all card(s) hit.\n"; sub parse{ @nums = ""; if ( /^(\d+):([\d\s]*)[\#]*.*$/ ){ $order = $1; @nums = split('\s',$2); } return 1; }