Closed p5pRT closed 22 years ago
@array = (1 .. 3); { local $#array = 6; print $#array\, "\n"; } print $#array\, "\n";
__END__ 6 6
I would have expected that either the second print would have printed 3\, or that the local would have caused an error.
Abigail
Abigail wrote:
[Please enter your report here]
@​array = \(1 \.\. 3\); \{ local $\#array = 6; print $\#array\, "\\n"; \} print $\#array\, "\\n"; \_\_END\_\_ 6 6
I would have expected that either the second print would have printed 3\, or that the local would have caused an error.
@array = (1 .. 3); print $#array\, "\n"; { local @array; $#array = 6; print $#array\, "\n"; } print $#array\, "\n";
__END__ 2 6 2
Under no circumstances should anything print 3 here. ;~)
It appears that the assignment (which autovivifies the array size) predates the localization; is that a bug? Should local bind more tightly than anything else?
John
-- John Peacock Director of Information Research and Technology Rowman & Littlefield Publishing Group 4720 Boston Way Lanham\, MD 20706 301-459-3366 x.5010 fax 301-429-5747
It appears that the assignment (which autovivifies the array size) predates the localization; is that a bug? Should local bind more tightly than anything else?
This looks like Yet Another People Want A Full Rollback System Which local() Ain't. (The recent local vs tie discussion is another example.)
In other words: people localize X where X has side effects in addition to just the value\, and they expect all the side effects of X to become magically undone at the scope exit. (Or\, presumedly\, at a new local() in the same scope.) Unless there is a full transactional thing going on underneath\, ain't gonna happen.
-- $jhi++; # http://www.iki.fi/jhi/ # There is this special biologist word we use for 'stable'. # It is 'dead'. -- Jack Cohen
In article \20020711203125\.S1007@​alpha\.hut\.fi\, Jarkko Hietaniemi \jhi@​iki\.fi wrote:
It appears that the assignment (which autovivifies the array size) predates the localization; is that a bug? Should local bind more tightly than anything else?
This looks like Yet Another People Want A Full Rollback System Which local() Ain't. (The recent local vs tie discussion is another example.)
In other words: people localize X where X has side effects in addition to just the value\, and they expect all the side effects of X to become magically undone at the scope exit. (Or\, presumedly\, at a new local() in the same scope.) Unless there is a full transactional thing going on underneath\, ain't gonna happen.
I don't think Abigail expected anything unreasonable; either "local $#..." should work (for some value of work) or give an syntax error (the way "local *FOO{BAR}" does\, for instance).
Yitzchak Scott-Thoennes wrote:
I don't think Abigail expected anything unreasonable; either "local $#..." should work (for some value of work) or give an syntax error (the way "local *FOO{BAR}" does\, for instance).
I don't think it would be unreasonable for the parser to treat this
local $#array = 6;
as if it were
local @array; $#array = 6;
but it just doesn't right now. Patches welcome (after 5.8.0 is released of course;~)...
John
John Peacock wrote:
Yitzchak Scott-Thoennes wrote:
I don't think Abigail expected anything unreasonable; either "local $#..." should work (for some value of work) or give an syntax error (the way "local *FOO{BAR}" does\, for instance).
I don't think it would be unreasonable for the parser to treat this
local $\#array = 6;
as if it were
local @​array; $\#array = 6;
ITYM\, it should be treated as if it were: local @array = @array; $#array = 6;
Perlsonally\, though\, I'd prefer it be as if it were treated as: my $old = $#array; LAST { $#array = $old }; $#array = 6;
But with the old value stored on the stack\, rather than in a variable.
but it just doesn't right now. Patches welcome (after 5.8.0 is released of course;~)...
John
-- tr/`4/ /d\, print "@{[map --$| ? ucfirst lc : lc\, split]}\,\n" for pack 'u'\, pack 'H*'\, 'ab5cf4021bafd28972030972b00a218eb9720000';
In article \3D310162\.81F40F10@​earthlink\.net\, Benjamin Goldberg \goldbb2@​earthlink\.net wrote:
John Peacock wrote:
Yitzchak Scott-Thoennes wrote:
I don't think Abigail expected anything unreasonable; either "local $#..." should work (for some value of work) or give an syntax error (the way "local *FOO{BAR}" does\, for instance).
local(keys %x) is a better example since that is an lvalue and *FOO{BAR} isn't (but ought to be!).
I don't think it would be unreasonable for the parser to treat this
local $\#array = 6;
as if it were
local @​array; $\#array = 6;
ITYM\, it should be treated as if it were: local @array = @array; $#array = 6;
Since you can explicitly do either of those\, I don't see the point. I'd rather see a syntax error.
Perlsonally\, though\, I'd prefer it be as if it were treated as: my $old = $#array; LAST { $#array = $old }; $#array = 6;
But with the old value stored on the stack\, rather than in a variable.
That's more what I'd expect it to do. But it doesn't seem worthwhile to make it work since\, if I recall correctly\, $# will go away for Perl6.
Yitzchak Scott-Thoennes wrote:
ITYM\, it should be treated as if it were: local @array = @array; $#array = 6;
Since you can explicitly do either of those\, I don't see the point. I'd rather see a syntax error.
Uh\, but there should be more than one way to do it.
Perlsonally\, though\, I'd prefer it be as if it were treated as: my $old = $#array; LAST { $#array = $old }; $#array = 6;
But with the old value stored on the stack\, rather than in a variable.
That's more what I'd expect it to do. But it doesn't seem worthwhile to make it work since\, if I recall correctly\, $# will go away for Perl6.
But not the ability to get the length of an array as a lvalue :
temp @foo.length;
Is there a good mailing list for PERL programming questions? I could not seem to find one...
Any suggestions?
Chip Cuntz Worldcom v622.1305/719.535.1305
On Mon\, 15 Jul 2002 16:47:04 -0600\, Chip Cuntz \chipperc\.cuntz@​wcom\.com said:
CC> Is there a good mailing list for PERL programming questions? I could not CC> seem to find one...
It is not maillist but try http://www.perlmonks.org/.
-- Ilya Martynov (http://martynov.org/)
@abigail - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#10041 (status was 'resolved')
Searchable as RT10041$