in reply to Re: Two Range Operator Anomalies
in thread Two Range Operator Anomalies
The documentation "The range operator (in list context) makes use of the magical auto-increment algorithm if the operands are strings." didn't quite shed any light on it, as I'm already familiar with the magical auto-increment feature. (But I think hbm got it below, which clarified something that the documenation could possibly use better wording for).
As to the second, however, you say the workaround is to use a "modifiable copy":
for ('a'..'f') { my $letter = $_; # Make modifiable copy ... }
But why isn't the my that I'm using here:
foreach my $letter ('a' ... 'c', 'd' ... 'f') { print " $letter"; $letter = uc $letter; }
doing exactly that??
Update: Actually, I see why. Of course, because it's assigning to a modifiable lvalue of the variable. Never mind.
But I'm still curious why this:
#!/usr/bin/perl -w use strict; use warnings; sub letters { foreach my $letter ('a' ... 'c') { print " $letter"; $letter = uc $letter; } print "\n"; } letters(); letters(); letters();
Doesn't exhibit the same behavior? Is it simply that it doesn't undergo the same optimization step you referred to?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Two Range Operator Anomalies
by ikegami (Patriarch) on Mar 11, 2009 at 16:32 UTC |