on 11/11/2000 05:54 PM, Bart Lateur at bart.lateur@skynet.be wrote: > On Sat, 11 Nov 2000 04:30:26 -0500, Scott R. Godin wrote: > >> perl 5.004 doesn't understand the sort of >> my $forwards .= for ('a'..'z'); >> context (sigh) that you later version users have, > > Nope. You must be referring to: > > my $forwards .= $_ for ('a' .. 'z'); yeah, but it was my (perhaps foolish) understanding that the $_ would be 'understood' in this context, as it is in several others. *shrug* :) live and learn, always. Is there any listing anywhere of places where $_ is most decidedly NOT 'understood' in places where you might think it would be, (so that I can stuff the space between my ears with more useful info)? (: >> and if I use >> my $forwards = 'a'..'z'; >> I get non-numeric errors in 'flip' and 'flop' whatever they are. > > The '..' operator in a scalar context is a logical test, but with > built-in memory. For example: > > for my $i (1 .. 10) { > print "$i\n" if $i==5 .. $i==8 > } > --> > 5 > 6 > 7 > 8 > > Now, what does this do? Well, first it attempts to do a test on the > left side of the '..'. Until this succeeds, the result is false. As soon > as this succeeds, *once*, the right side is being the crucial test. The > whole expression is true (that's the memory part), until the right side > becomes true, which is the final case. After that, the memory is > cleared. after that, it's the left side again that matters. > > So, as a whole, the condition is false until $i==5, and then it stays > true until (and including) $i==8. AHhhhhhh, okay, I understand that.. thank you for the detailed explanation.. NOW I see how that works, and damn, that's a nice short-circuit. I'll definitely have to remember that little trick. :) > As for your problem, I think I'd do: > > my %replace; > @replace{'a' .. 'z'} = reverse 'a' .. 'z'; > s/([a-z])/$replace{$1}/g; works for me, definitely, although I wound up doing it more like this, due to what I wanted: my %replace; @replace{'a' .. 'z'} = reverse 'a' .. 'z'; @replace{'0' .. '9'} = reverse '0' .. '9'; #elsewhere $coercename =~ s/([a-z]|[0-9])/$replace{$1}/g; the resultant yield again sorts properly, although It has been my understanding that tr/// was a great deal faster than s/// I'd have to run some benchmarking to be sure, but I get the impression that I'm still losing out here time-wise. if the CGI takes a lot of hits, the time can potentially stack up against me, at least in my understanding. any thoughts? -- Scott R. Godin | e-mail : mactech@webdragon.net Laughing Dragon Services | web : http://www.webdragon.net/ # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org