Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Play and win the word morph game with the help of Perl :)

by jwkrahn (Abbot)
on Jun 29, 2006 at 09:02 UTC ( [id://558262]=note: print w/replies, xml ) Need Help??


in reply to Play and win the word morph game with the help of Perl :)

Here are a couple of minor optimisations:

1)  In the transform sub you copy the contents of the @words array unnecessarily. Change:

50 my @words = @{+shift}; 72 foreach my $word (@words) { 95 foreach my $word (@words) {
To:
50 my $words = shift; 72 foreach my $word (@$words) { 95 foreach my $word (@$words) {
2)  The four argument form of substr is more efficient then assigning to the three argument form of substr. Change:
118 substr((my $pat = $word), $i, 1) = '.';
To:
118 substr my $pat = $word, $i, 1, '.';

HTH

Replies are listed 'Best First'.
Re^2: Play and win the word morph game with the help of Perl :)
by Ieronim (Friar) on Jun 29, 2006 at 11:11 UTC
    (2) accepted, (1) - not accepted.

    (1) makes no measurable differece of speed, as the array is copied only once; i left my variant because it simply looks cleaner for me :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found