logo       

Re: Solutions and Discussion for Perl Quiz of the Week #17: msg#00003

Subject: Re: Solutions and Discussion for Perl Quiz of the Week #17
On Jun 1, 2004, at 1:07 PM, Mark Jason Dominus wrote:

(Pr. Gray's was about the same length, and was beautifully straightforward, except for one line in the middle that gave me the willies. But it's worth looking at.)

I warned that my Search-In-One-Variable-Replace-In-Another trick was probably bad style. Apparently MJD agrees. <laughs>

Surprisingly, it seemed natural at the time and was the first thing I thought of. I know, there's probably drugs for that and I'll look into them.

I appreciate MJD's praise though, so I'll pay him back with a cleaner solution. Replacing the scary:

        $limit-- unless
                $word =~ s/($letter)/substr $puzzle, pos($word), 1, $1; $1;/ige;

with the sane:

        for my $i (0..(length($word) - 1)) {
                my $test = substr $word, $i, 1;
                substr $puzzle, $i, 1, $test if lc $letter eq lc $test;
        }
        $limit-- unless $word =~ m/$letter/i;

works just fine and I'll bet it gives MJD (and others) less "willies".

Just to be clear, the first method is bad because it's using a construct for its side effects only. You can see this in the fact that I have to tack on an extra $1 at the end of the replace, to keep from mangling the original words with my trick.

I repent my wicked ways.  Forgive me.

James




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe