dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm stumped on an issue that shouldn't be very complex, but I'm having a difficult time coming up with a solution
I build an array of hashes that reads thru a global holiday calendar and populates it with only US & CA holiday dates. Once i have the array of hashes populated I want to remove any holiday dates they both share. For example, they both share 20121225 as xmas holiday. In this case i would like it removed from the array of hashes.
#!/usr/bin/env perl use warnings; use strict; my %countries; my %seen; my @dup; my @countries; my $holiday; my @cntry_of_issue = ('US','CA'); while (<DATA>) { chomp; next if /^\s*$/ || /^\#/; my $aref = [split /,/, $_]; push( @{$countries{$aref->[2]}}, $aref->[5]); } sub strip_US_CA_dup_hols { for (@cntry_of_issue) { foreach $holiday (@{$countries{$_}}) { $seen{$holiday}++; } }#end of for while ( my ($key, $value) = each %seen ) { push @dup,$key if $value > 1; } for (@cntry_of_issue) { delete $@{$countries{$_}} if grep /@{$countries{$_}}/, @dup; } }#end of function &strip_US_CA_dup_hols; __DATA__ 808,XNYS,US,New York Stock Exchange,2012,20120102,Mon,New Year's Day O +BS,T 808,XNYS,US,New York Stock Exchange,2012,20120116,Mon,Martin Luther Ki +ng Jr. Day,T 808,XNYS,US,New York Stock Exchange,2012,20120220,Mon,Presidents' Day, +T 808,XNYS,US,New York Stock Exchange,2012,20120406,Fri,Good Friday,T 808,XNYS,US,New York Stock Exchange,2012,20120528,Mon,Memorial Day,T 808,XNYS,US,New York Stock Exchange,2012,20120704,Wed,Independence Day +,T 808,XNYS,US,New York Stock Exchange,2012,20120903,Mon,Labor Day,T 808,XNYS,US,New York Stock Exchange,2012,20121122,Thu,Thanksgiving,T 808,XNYS,US,New York Stock Exchange,2012,20121225,Tue,Christmas,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120102,Mon,New Year's Day OB +S,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120220,Mon,Family Day,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120406,Fri,Good Friday,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120521,Mon,Victoria/Patriots +' Day,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120702,Mon,Canada Day OBS,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120806,Mon,Civic Holiday,T 665,XTSE,CA,Toronto Stock Exchange,2012,20120903,Mon,Labour Day,T 665,XTSE,CA,Toronto Stock Exchange,2012,20121008,Mon,Thanksgiving,T 665,XTSE,CA,Toronto Stock Exchange,2012,20121225,Tue,Christmas,T 665,XTSE,CA,Toronto Stock Exchange,2012,20121226,Wed,Boxing Day,T
I sent and earlier post that was not correct by mistake. This one is actually legible. Any help would be greatly appreciated. Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete Duplicate CA & US holidays
by GrandFather (Saint) on Mar 01, 2012 at 22:22 UTC | |
|
Re: Delete Duplicate CA & US holidays
by Corion (Patriarch) on Mar 01, 2012 at 21:05 UTC | |
|
Re: Delete holiday from array of hashes when US & CA share a holiday
by tangent (Parson) on Mar 01, 2012 at 21:21 UTC | |
|
Re: Delete Duplicate CA & US holidays
by JavaFan (Canon) on Mar 01, 2012 at 21:07 UTC |