fork download
  1. #!/usr/bin/perl
  2.  
  3. # Idiom #250 Pick a random value from a map
  4. # https://p...content-available-to-author-only...s.org/idiom/250
  5.  
  6. use v5.10;
  7.  
  8. $k = 'A';
  9. $m{ $k++ } = ++$v for 1..26;
  10.  
  11. @vals = values %m;
  12. $x = $vals[ int rand @vals ];
  13.  
  14. say 'random pick was ', $x;
  15.  
  16.  
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
random pick was 12