SPUG: apre SPUG attributes [was Re: useless brevity]

Michael R. Wolf MichaelRunningWolf at att.net
Mon Nov 25 03:12:02 CST 2002


m3047 at inwa.net (Fred Morris) writes:

> >On Thu, Nov 21, 2002 at 06:00:47PM -0800, Fred Morris wrote:
> >>[...]
> >> eval join( ' && ', map $place->{$_}, ('beer','quiet','udist') );
> 
>    eval join( ' && ', @{$place}{'beer','quiet','udist'} );
> 
> For some reason taking a slice of a hash reference escaped me the first
> time... maybe because it's harder to grok, or is that just me? :-\

As long as you're slicing, here's how I'd model it.  Of course, you
can see my preference for smoke-free and talkable.  

What values would you (we) choose for $threshhold, %importance?  

And who knows real keys values for %apre_attributes?

#! /usr/bin/perl -w

my $threshhold = 70;
my %importance = (udist      => 10,
		  beer       => 5,
		  talkable   => 20,
		  breathable => 50
		 );

my %apre_attributes = ( 
		       McCools 		=> [qw(udist beer)],
		       "Hale's Brew Pub"   => [qw(beer)],
		       # In Heaven, there is no beer.
		       # That's why we drink it here.
		       # 'Cause when we're gone from here,
		       # our friends will be drinkin' all the beer.
		       Heaven  		=> [qw(talkable breathable)],
		       Hell    		=> [qw(beer)],
		       "London Underground" => [],
		       ### Your suggestions go here.....
		       # ...
		       # ...
		      );

foreach $establishment (sort keys %apre_attributes) {
    my $affinity = eval join "+" => 
      (0,  @importance{ @{$apre_attributes{$establishment}} } );
    $OK = ($affinity >= $threshhold) ? "+" : "-";
    push @proposals, [$affinity, $OK, $establishment];
}

map {printf "%3d %1s %s\n" => @{$_->[1]}[0..2] }
  sort {$b->[0] <=> $a->[0] }
  map {[$_->[0], $_]} @proposals;


-- 
Michael R. Wolf
    All mammals learn by playing!
        MichaelRunningWolf at att.net


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list