Hi, I'm picking the field the way I want from a flatfile database in Perl.
However I do not know how to get rid of the duplicates.
Code:
use strict;
use warnings;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";
foreach my $rec (<DATA>) {
my @fd=split /\|/, "$rec";
my $dt=$fd[3];
my @tmm = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
my $tyr = substr $dt,0,+4; # year (nums 1-4)
my $tmo = substr $dt,4,+2; # month (nums 5&6)
$tmo=$tmo-1; # compensate for 0 in month
my $dts = "$tmm[$tmo] $tyr";
print qq ~<a href="#">$dts</a><br>~; # How do I stop the duplicates?
}
exit(0);
=holdResults
This is how it shows with the duplicates
Jan 2012
Jan 2012
Dec 2011
Dec 2011
Nov 2010
It should show
Jan 2012
Dec 2011
Nov 2010
=cut
__DATA__
5|EEE|eeeeee|201201|
4|DDD|dddddd|201201|
3|CCC|cccccc|201112|
2|BBB|bbbbbb|201112|
1|AAA|aaaaaa|201011|
We did try something about repeats a year or so back,
Code:
my $dts{$_}++; next if $dts{$_} > 1;
but I think there's an error in it (not sure how to use it anyways).
my %occurred;
foreach my $rec (<DATA>) {
my @fd=split /\|/, "$rec";
my $dt=$fd[3];
my @tmm = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
my $tyr = substr $dt,0,+4; # year (nums 1-4)
my $tmo = substr $dt,4,+2; # month (nums 5&6)
$tmo=$tmo-1; # compensate for 0 in month
my $dts = "$tmm[$tmo] $tyr";
next if $occurred{$dts};
$occurred{$dts} = 1;
print qq ~<a href="#">$dts</a><br>~; # How do I stop the duplicates?
}
Bookmarks