Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Trouble grepping values when hash contains multiple values per key

by dirtdog (Beadle)
on Jun 05, 2010 at 16:55 UTC ( #843278=note: print w/ replies, xml ) Need Help??


in reply to Re: Trouble grepping values when hash contains multiple values per key
in thread Trouble grepping values when hash contains multiple values per key

Thanks Toolic

When i pasted the code in, some of the syntax got messed up, specifically the curly braces, but i did have the same syntax that you had

I ran what you had and it did work beautifully

ultimately, i'm trying to get the following piece of code to work. Basically, I have my date and i check it against the calendar file to see if the date is a holiday...if it does exist it means it's a holiday so i increment the date by 1 day (unless it's a sat or sun..then i increment it until it's not sat or sun..this piece of logic works), then i check the newly incremented date against the holiday file again. I repeat this until it doesn't exist in the holiday file. Then i know i have a date that's not a holiday.

The following code for some reason is not working for me. It's hitting the until loop but not entering it even if the newly incremented date is also a date in the holiday file

You may need to mock up the holiday config file with back to back holiday's to create the scenario

$date='20100101'; $new_date=get_next_bus_day($date);
until (my @date = grep !/$new_date/,@{$countries${cntry_of_issue}}) { $new_date=get_next_bus_day($new_date); }
sub get_next_bus_day { my $inc=1; my $inc4sat=2; my $inc4fri=3; my $new_date; my $date=shift; DEBUG > 1 and print "date is: >$date<\n"; my $y = substr($date,0,4); my $m = substr($date,4,2); my $d = substr($date,6,2); my $time = timelocal("", "", "", $d, $m-1, $y); if ((localtime($time))[6] == 5) { $new_date=strftime "%Y%m%d", localtime timelocal(0,0,0,$d,$m-1,$y) + +($inc4fri * 24 * 60 * 60); } elsif ((localtime($time))[6] == 6) { $new_date=strftime "%Y%m%d", localtime timelocal(0,0,0,$d,$m-1,$y) + +($inc4sat * 24 * 60 * 60); } else { $new_date=strftime "%Y%m%d", localtime timelocal(0,0,0,$d,$m-1,$y) + +($inc * 24 * 60 * 60); } return $new_date; }

Do you see any obvious reason why this wouldn't work?


Comment on Re^2: Trouble grepping values when hash contains multiple values per key
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://843278]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-12-19 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (83 votes), past polls