[boulder.pm] activity on this list
Hank Turowski
hank.turowski at firstworld.net
Fri Jan 21 12:43:14 CST 2000
At 09:17 AM 1/21/00 -0700, you wrote:
> #!/usr/bin/perl -w
>
> use strict;
>
> my @opinions = ( "yes", "no" );
> my $baz = $opinions[ rand @opinions ];
>
> if ( $baz eq "yes" ) {
> print "foo\n";
> } else {
> print "bar\n";
> }
>
>I'm wondering how many reasonably different ways the logic expressed in
>the if/else code could have been written.
>
> $baz eq "yes" ? print "foo\n" : print "bar\n";
>
>Any others?
>
>
>Walter
my %response = ( yes=>"foo", no=>"bar");
my @options = keys(%response);
my $baz = $options[rand @options];
print ($response{$baz} || "bar"), "\n";
Given that we KNOW $baz will be "yes" or "no", I could have used
print "$response{$baz}\n";
but in order to truly model the else portion of your conitional I had to
include the || "bar" in the print. Maybe something can change $baz
before the print?
Hank Turowski
More information about the Boulder-pm
mailing list