Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Conditional within Hash definition

by Random_Walk (Prior)
on Jan 28, 2014 at 16:50 UTC ( [id://1072381]=note: print w/replies, xml ) Need Help??


in reply to Conditional within Hash definition

If you run to more than two conditions, you can use a mapping hash

use strict; use warnings; # the simple case, as requested my $rain = int rand 2; my %rain_map = ( 0 => 'dry', 1 => 'wet', ); my %Weather = ( precipitation => $rain_map{$rain} ); print "Simple weather($rain) is $Weather{precipitation}\n"; # a little more my $precip = int rand 5; my %precip_map = ( 0 => 'dry', 1 => 'wet fog', 2 => 'wet rain', 3 => 'wet hail', 4 => 'plague of locusts', ); my %More_Weather = ( precipitation => $precip_map{$precip} ); print "More weather($precip) is $More_Weather{precipitation}\n";

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: Conditional within Hash definition
by tangent (Parson) on Jan 28, 2014 at 17:06 UTC
    Wet rain? that would be the type that soaks you instantly, as opposed to dry rain where even though you can see it you don't seem to get wet. You also have hard and soft rain, and the rain can come in sheets or buckets, or can be spitting, lashing, pissing, driving, teeming, or pelting. And that's all just in one day in Ireland, though we get lots of rainbows too.

      Aye, then we can go off on a tangent about the inuit's alleged 200 words for snow...

      I was actualy using rain as a qualifier for wet, rather than wet as a qualifier for rain. Fog and snow can be wet too. I guess I could have added dry snow if its cold enough too.

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!

        But please be very careful with your Dry Ice. That could wipe our whole ecosystem. Thank You.

Re^2: Conditional within Hash definition
by veryan (Initiate) on Jan 28, 2014 at 16:58 UTC

    That's really helpful because it was going to be my next question ;) Many thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found