Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Looking for pointers or optimizations.

by hbm (Hermit)
on Aug 21, 2012 at 14:23 UTC ( #988755=note: print w/ replies, xml ) Need Help??


in reply to Looking for pointers or optimizations.

1. Instead of this:

my $displayed; foreach my $s (split(//, $word)) { if (exists($correct_guesses{$s})) { $displayed .= $s; } else { $displayed .= "*"; } $displayed .= " "; }

This?

my $displayed = join" ", map { exists $correct_guesses{$_} ? $_ : '*' } split//, $word;

2. And instead of this:

print "Fails remaining: $turns\n"; print "Wrong guesses: ", join(" ", keys %wrong_guesses), "\n"; print "Your guess: ";

This?

print "Fails remaining: $turns\n", "Wrong guesses: ", join(" ", keys %wrong_guesses), "\n", "Your guess: ";

3. And instead of this:

if (!$guess =~ /[a-z]/ ...

This?

if ($guess !~ /[a-z]/ ...


Comment on Re: Looking for pointers or optimizations.
Select or Download Code
Re^2: Looking for pointers or optimizations.
by thmsdrew (Scribe) on Aug 21, 2012 at 14:36 UTC

    In response to you first one, I have a similar optimization but a bit less confusing to me:

    my $displayed; foreach my $s (split(//, $word)) { $displayed .= exists($correct_guesses{$s}) ? "$s " : "* "; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-07-14 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls