Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Perl Script for this requiremnet

kiran1977
Occasional Contributor

Need Perl Script for this requiremnet

In a Data file with delemtier "|"
first field is Store Number and the 4th field is Coupon type.
there are different types of coupons like type '2','3','4','7'.

i need a script generating unique store number with apporpiate count of coupons values

Sample Data:

200|3456|234|3
200|3456|234|3
200|3462|123|2
300|3456|567|4

Output should be :
Store number cpn 2| cpn 3|cpn4
200 1 | 2 | 0
300 0 | 0 | 1
1 REPLY
Hein van den Heuvel
Honored Contributor

Re: Need Perl Script for this requiremnet

Hmmm, much the same problem as:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=946013

Thanks for providing clear input and output definitions.

Since I had the test script still floating around... this should be close...

$file = "x2.txt";
open (INP, "<$file" ) or die "$file: $!";
while () {
my ($key, $coupon) = (split /\s*\|\s*|$/)[0,3];
$valid_coupons{$coupon}++;
$stores{$key}++;
$counters{"$key $coupon"}++;
}
close INP;
print "Store number";
foreach my $coupon (sort keys %valid_coupons) {print "| cpn $coupon"} ;
print "\n";
foreach my $key (sort keys %stores) {
print "SN=$key";
foreach my $coupon (sort keys %valid_coupons) {
printf (" | %d ", $counters{"$key $coupon"});
}
print "\n";
}