Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

5.6.0 makes SCALAR typeglob entry for ARRAYS #2410

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#3767 (status was 'resolved')

Searchable as RT3767$

p5pRT commented 24 years ago

From gnat@frii.com

This​:

  @​foo = (1..10);   print *foo{SCALAR}\,*foo{ARRAY}\,*foo{HASH};

prints this​:

  SCALAR(0xac7b4)ARRAY(0xac7c0)

with perl 5.6.0 and 5.004_04.

Nat

p5pRT commented 24 years ago

From @mjdominus

This​:

@​foo = (1..10);

prints this​:

SCALAR(0xac7b4)ARRAY(0xac7c0)

The array assignment is a red herring there. Typeglobs always have a scalar part; regardless of whether or not there is an array. Your code\, without the array assignment​:

  print *foo{SCALAR}\,*foo{ARRAY}\,*foo{HASH};

prints this​:

  SCALAR(0xac7b4)

My recollection from the last time this came up is that this is an optimization​: Larry supposed that scalars would be common\, and so when a glob is allocated the scalar part is allocated at the same time.

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

On Aug 20\, Nathan Torkington said​:

@​foo = (1..10); print *foo{SCALAR}\,*foo{ARRAY}\,*foo{HASH};

prints this​:

SCALAR(0xac7b4)ARRAY(0xac7c0)

From perlref​:

  *foo{THING} returns undef if that particular THING   hasn't been used yet\, except in the case of scalars.   *foo{SCALAR} returns a reference to an anonymous scalar   if $foo hasn't been used yet. This might change in a   future release.