
omega
Novice
Dec 3, 2012, 2:50 AM
Post #1 of 3
(2179 views)
|
hash copy only getting 1922 of 1932, no duplicates in read file
|
Can't Post
|
|
After debuging I found the issue to be in: if ($month =~ /\d\d/) { # keep double digit months $just = "$year" . '_' . "$month" . '_' . "$day"; $new_numbers{$just} = "$numbers{$bookmark}"; } else { # change single digit months to include a '0' ($new_month = $month) =~ s/(\d)/0\1/; $work = "$year" . '_' . "$new_month" . '_' . "$day"; $new_numbers{$work} = "$numbers{$bookmark}"; } where this code sees to be finding duplicates but the above portion finds none. How can one hash have a duplicate key if the original hash is only having a 0 added on to single digit numerals? below is the complete code: #!/usr/bin/perl # 1932 open LOTTO, '<', 'lotto.txt' # make 'lotto.txt' the sample file or die "couldnt open file"; while ( <LOTTO> ) { # open every line of 'lotto.txt' @trial1 = split /\s+/, "$_"; # remove all the spaces $trial2 = "@trial1"; # change array to scalar if ( $trial2 =~ m{(\d+)/(\d+)/(\d+).*(\d+)/(\d+)/(\d+)} ) { $dates_one = "$1_$2_$3"; # look for date 1 in current line $dates_two = "$4_$5_$6"; # look for date 2 in current line } if ( $trial2 =~ /(\d+) - (\d+) - (\d+) - (\d+) - (\d+) - (\d+).*(\d+) - (\d+) - (\d+) - (\d+) - (\d+) - (\d+)/ ) { $numbers{$dates_one} = "$1-$2-$3-$4-$5-$6"; # look for numbers 1 in current line $numbers{$dates_two} = "$7-$8-$9-$10-$11-$12"; # look for numbers 2 in current line } } foreach (keys %numbers) { # formating program ( dates ) $bookmark = "$_"; if (/(\d+)_(\d+)_(\d+)/) { $month = $1; $day = $2; $year = $3; if ($month =~ /\d\d/) { # keep double digit months $just = "$year" . '_' . "$month" . '_' . "$day"; $new_numbers{$just} = "$numbers{$bookmark}"; } else { # change single digit months to include a '0' ($new_month = $month) =~ s/(\d)/0\1/; $work = "$year" . '_' . "$new_month" . '_' . "$day"; $new_numbers{$work} = "$numbers{$bookmark}"; } } } foreach (keys %new_numbers) { # formating program ( numbers ) $bookmark = "$_"; if ($new_numbers{$bookmark} =~ /(\d+)-(\d+)-(\d+)-(\d+)-(\d+)-(\d+)/) { $one = $1; $two = $2; $three = $3; $four = $4; $five = $5; $six = $6; if ($one =~ /\d\d/) { # change single digit pairs to include a '0' } else { $one = '0' . "$one"; } if ($two =~ /\d\d/) { } else { $two = '0' . "$two"; } if ($three =~ /\d\d/) { } else { $three = '0' . "$three"; } if ($four =~ /\d\d/) { } else { $four = '0' . "$four"; } if ($five =~ /\d\d/) { } else { $five = '0' . "$five"; } if ($six =~ /\d\d/) { } else { $six = '0' . "$six"; } $new_numbers{$bookmark} = "$one-$two-$three-$four-$five-$six"; } } foreach ( sort keys %new_numbers ) { # sorting program ( pre-y2k ) $bookmark = "$_"; if ( /(\d+)_\d+_\d+/ ) { $year = $1; if ( $year > 13 ) { print "$bookmark: $new_numbers{$bookmark}\n"; } } } foreach ( sort keys %new_numbers ) { # sorting program ( post-y2k ) $bookmark = "$_"; if ( /(\d+)_\d+_\d+/ ) { $year = $1; if ( $year < 13 ) { print "$bookmark: $new_numbers{$bookmark}\n"; } } }
|