Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local($#array) is not local :( #4261

Open
p5pRT opened this issue Jul 31, 2001 · 8 comments
Open

local($#array) is not local :( #4261

p5pRT opened this issue Jul 31, 2001 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 31, 2001

Migrated from rt.perl.org#7411 (status was 'open')

Searchable as RT7411$

@p5pRT
Copy link
Author

p5pRT commented Jul 31, 2001

From jefpin@towers.crusoe.net

  @​a = (1..5);
  {
  local $#a = 2;
  print "@​a\n";
  }
  print "@​a\n";

  __END__
  1 2 3
  1 2 3

That's a bit discouraging.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.7.2:

Configured by jefpin at Tue Jul 31 12:20:33 EDT 2001.

Summary of my perl5 (revision 5.0 version 7 subversion 2 patch 11471) configuration:
  Platform:
    osname=linux, osvers=2.2.16-3, archname=i586-linux
    uname='linux towers.crusoe.net 2.2.16-3 #5 sat jul 8 11:42:18 edt 2000 i586 unknown '
    config_args='-Dprefix=/tmp/bleadperl -Dusedevel -DDEBUGGING -de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=define
  Compiler:
    cc='cc', ccflags ='-Wall -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-Wall -fno-strict-aliasing'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    libc=undef, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    DEVEL11466


@INC for perl v5.7.2:
    /tmp/bleadperl/lib/5.7.2/i586-linux
    /tmp/bleadperl/lib/5.7.2
    /tmp/bleadperl/lib/site_perl/5.7.2/i586-linux
    /tmp/bleadperl/lib/site_perl/5.7.2
    /tmp/bleadperl/lib/site_perl
    .


Environment for perl v5.7.2:
    HOME=/home/jefpin
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin:/home/jefpin/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Aug 5, 2001

From @schwern

Hmmm. Doesn't even do what I thought it would do (ie. return $#a to
5 but leave @​a[3,4] empty). What should it do?

Anyhow, you can get the desired effect with​:

  @​a = (1..5);
  {
  local @​a = @​a[0..2];
  print "@​a\n";
  }
  print "@​a\n";

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2011

From @Leont

On Tue Jul 31 05​:05​:12 2001, jefpin@​towers.crusoe.net wrote​:

[Please enter your report here]

@​a = (1..5);
{
local $#a = 2;
print "@​a\n";
}
print "@​a\n";

__END__
1 2 3
1 2 3

That's a bit discouraging.

I'm not sure there's a sane way to support this. At the very least we
could this warn. It's really easy to do at runtime and shouldn't be too
hard at compile-time either, I think.

Leon

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2011

From @cpansprout

On Sun Dec 11 11​:41​:31 2011, LeonT wrote​:

On Tue Jul 31 05​:05​:12 2001, jefpin@​towers.crusoe.net wrote​:

[Please enter your report here]

@​a = (1..5);
{
local $#a = 2;
print "@​a\n";
}
print "@​a\n";

__END__
1 2 3
1 2 3

That's a bit discouraging.

I'm not sure there's a sane way to support this.

We could make it work like tied variables. ...Ahem, but without the bugs
(#104118) of course.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2011

From @doy

On Sun, Dec 11, 2011 at 11​:41​:32AM -0800, Leon Timmermans via RT wrote​:

On Tue Jul 31 05​:05​:12 2001, jefpin@​towers.crusoe.net wrote​:

[Please enter your report here]

@​a = (1..5);
{
local $#a = 2;
print "@​a\n";
}
print "@​a\n";

__END__
1 2 3
1 2 3

That's a bit discouraging.

I'm not sure there's a sane way to support this. At the very least we
could this warn. It's really easy to do at runtime and shouldn't be too
hard at compile-time either, I think.

Couldn't we just turn "local $#a = 2" into "local @​a = @​a[0..2]"? That
has well defined semantics, and seems to be what the intent is.

-doy

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2011

From @cpansprout

On Sun Dec 11 12​:14​:18 2011, doy@​tozt.net wrote​:

On Sun, Dec 11, 2011 at 11​:41​:32AM -0800, Leon Timmermans via RT wrote​:

On Tue Jul 31 05​:05​:12 2001, jefpin@​towers.crusoe.net wrote​:

[Please enter your report here]

@​a = (1..5);
{
local $#a = 2;
print "@​a\n";
}
print "@​a\n";

__END__
1 2 3
1 2 3

That's a bit discouraging.

I'm not sure there's a sane way to support this. At the very least we
could this warn. It's really easy to do at runtime and shouldn't be too
hard at compile-time either, I think.

Couldn't we just turn "local $#a = 2" into "local @​a = @​a[0..2]"? That
has well defined semantics, and seems to be what the intent is.

We could, but the localised tie mechanism already exists, so my
suggestion (apart from fixing bugs) would be a matter of tweaking an
if() condition. Also, local @​a = @​a[0..2] would have slightly different
behaviour on sparse arrays.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2011

From @ikegami

On Sun, Dec 11, 2011 at 2​:41 PM, Leon Timmermans via RT <
perlbug-followup@​perl.org> wrote​:

On Tue Jul 31 05​:05​:12 2001, jefpin@​towers.crusoe.net wrote​:

[Please enter your report here]

@​a = (1..5);
{
local $#a = 2;
print "@​a\n";
}
print "@​a\n";

__END__
1 2 3
1 2 3

That's a bit discouraging.

I'm not sure there's a sane way to support this. At the very least we
could this warn. It's really easy to do at runtime and shouldn't be too
hard at compile-time either, I think.

We do warn.

$ perl -wE'@​a=(0..4); { local $#a = 2; } say @​a; say $#a;'
Useless localization of array length at -e line 1.
012
2

5.14.0

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2011

From @cpansprout

On Sun Dec 11 13​:00​:15 2011, sprout wrote​:

On Sun Dec 11 12​:14​:18 2011, doy@​tozt.net wrote​:

On Sun, Dec 11, 2011 at 11​:41​:32AM -0800, Leon Timmermans via RT wrote​:

On Tue Jul 31 05​:05​:12 2001, jefpin@​towers.crusoe.net wrote​:

[Please enter your report here]

@​a = (1..5);
{
local $#a = 2;
print "@​a\n";
}
print "@​a\n";

__END__
1 2 3
1 2 3

That's a bit discouraging.

I'm not sure there's a sane way to support this. At the very least we
could this warn. It's really easy to do at runtime and shouldn't
be too
hard at compile-time either, I think.

Couldn't we just turn "local $#a = 2" into "local @​a = @​a[0..2]"? That
has well defined semantics, and seems to be what the intent is.

We could, but the localised tie mechanism already exists, so my
suggestion (apart from fixing bugs) would be a matter of tweaking an
if() condition. Also, local @​a = @​a[0..2] would have slightly different
behaviour on sparse arrays.

Oops. I thought you were replying to me, but you weren’t. I was
speaking in terms of the implementation. You were speaking in terms of
observable behaviour. We are in agreement.

--

Father Chrysostomos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant