Ovid has asked for the wisdom of the Perl Monks concerning the following question:
That code will assign "7" to $now. It seems to me that there should be a more "perlish" way to extract from the hash of hashes the greatest hash key that is less than or equal to $now. Can anyone help me come up with a clear example? (On the other hand, I don't want terribly obfuscated code).#!/usr/bin/perl -w use strict; my $now = 8; # we'll pretend it's between 8 and 9 PM my @hours; my %url = ( monday => { 1 => "Too early in the morning", 3 => "Someone came home from a bender", 7 => "Time for coffee", 16 => "Need to slack off the last hour of work" } ); # begin awkward code @hours = reverse (sort {$a <=> $b} keys %{$url{"monday"}}); foreach (@hours) { $now = $_, last if $_ <= $now; } # end awkward code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Hash of hashes question
by Russ (Deacon) on Jun 19, 2000 at 03:51 UTC | |
by merlyn (Sage) on Jun 19, 2000 at 03:56 UTC | |
by Russ (Deacon) on Jun 19, 2000 at 06:04 UTC | |
by Aighearach (Initiate) on Jun 19, 2000 at 11:56 UTC | |
by Russ (Deacon) on Jun 19, 2000 at 23:10 UTC | |
|