On Sunday 16 July 2006 07:26, Paul Johnson wrote:
> On Sun, Jul 16, 2006 at 05:48:10AM -0400, Daniel D Jones wrote:
> > It certainly does help.  I thought about substitution but couldn't
> > come up with a syntax.  This seems to be exactly what I was looking
> > for, but I'm running into a problem.  Here's code which demonstrates
> > it:
>
> [ ... ]
>
> > As you can see, the @values array is being shuffled to generate the
> > perms correctly.  However, the substitution seems to always be using
> > the original, unshuffled values.  Is it being cached somehow or what?
>
> Try printing out @tests when you print out @values.
>
> When you iterate through @tests, $test is an alias to the array elements
> rather than a copy of them.  So altering $test is changing @tests.  This
> is what you are seeing.

Ah!  Simple change:

sub runtests() {
        my $test;
        foreach (@tests) {
                $test = $_;
                $test =~ s/([a-z])/$values[ord($1) - ord('a')]/g;
                return 0 unless eval $test;
        }
        return 1;
}

Thanks!



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to