5 @INC = ('.', '../lib');
12 # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
16 is(join('',@ary), '12345');
18 $tmp = $ary[$#ary]; --$#ary;
21 is(join('',@ary), '1234');
24 $r = join(',', $#foo, @foo);
27 $r = join(',', $#foo, @foo);
30 $r = join(',', $#foo, @foo);
35 $r = join(',', $#bar, @bar);
38 $r = join(',', $#bar, @bar);
41 $r = join(',', $#bar, @bar);
44 $r = join(',', $#bar, @bar);
46 reset 'b' if $^O ne 'VMS';
49 $r = join(',', $#bar, @bar);
52 $r = join(',', $#bar, @bar);
55 $foo = 'now is the time';
56 ok(scalar (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)));
62 ok(!($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))))
63 or diag("$cnt $F1:$F2:$Etc");
65 %foo = ('blurfl','dyick','foo','bar','etc.','etc.');
67 is($bar{'foo'}, 'bar');
69 is($bar{'foo'}, undef);
70 (%bar,$a,$b) = (%foo,'how','now');
71 is($bar{'foo'}, 'bar');
72 is($bar{'how'}, 'now');
73 @bar{keys %foo} = values %foo;
74 is($bar{'foo'}, 'bar');
75 is($bar{'how'}, 'now');
77 @foo = grep(/e/,split(' ','now is the time for all good men to come to'));
78 is(join(' ',@foo), 'the time men come');
80 @foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
81 is(join(' ',@foo), 'now is for all good to to');
83 $foo = join('',('a','b','c','d','e','f')[0..5]);
86 $foo = join('',('a','b','c','d','e','f')[0..1]);
89 $foo = join('',('a','b','c','d','e','f')[6]);
92 @foo = ('a','b','c','d','e','f')[0,2,4];
93 @bar = ('a','b','c','d','e','f')[1,3,5];
94 $foo = join('',(@foo,@bar)[0..5]);
97 $foo = ('a','b','c','d','e','f')[0,2,4];
100 $foo = ('a','b','c','d','e','f')[1];
103 @foo = ( 'foo', 'bar', 'burbl');
105 no warnings 'deprecated';
110 # various AASSIGN_COMMON checks (see newASSIGNOP() in op.c)
115 is("@foo", "foo bar burbl blah"); # 38
118 is("@foo", "bar burbl blah"); # 39
120 @foo = ('XXX',@foo, 'YYY');
121 is("@foo", "XXX bar burbl blah YYY"); # 40
123 @foo = @foo = qw(foo b\a\r bu\\rbl blah);
124 is("@foo", 'foo b\a\r bu\\rbl blah'); # 41
126 @bar = @foo = qw(foo bar); # 42
127 is("@foo", "foo bar");
128 is("@bar", "foo bar"); # 43
130 # try the same with local
131 # XXX tie-stdarray fails the tests involving local, so we use
132 # different variable names to escape the 'tie'
134 @bee = ( 'foo', 'bar', 'burbl', 'blah');
138 is("@bee", "foo bar burbl blah"); # 44
140 local (undef,@bee) = @bee;
141 is("@bee", "bar burbl blah"); # 45
143 local @bee = ('XXX',@bee,'YYY');
144 is("@bee", "XXX bar burbl blah YYY"); # 46
146 local @bee = local(@bee) = qw(foo bar burbl blah);
147 is("@bee", "foo bar burbl blah"); # 47
149 local (@bim) = local(@bee) = qw(foo bar);
150 is("@bee", "foo bar"); # 48
151 is("@bim", "foo bar"); # 49
153 is("@bee", "foo bar burbl blah"); # 50
155 is("@bee", "XXX bar burbl blah YYY"); # 51
157 is("@bee", "bar burbl blah"); # 52
159 is("@bee", "foo bar burbl blah"); # 53
162 # try the same with my
165 is("@bee", "foo bar burbl blah"); # 54
167 my (undef,@bee) = @bee;
168 is("@bee", "bar burbl blah"); # 55
170 my @bee = ('XXX',@bee,'YYY');
171 is("@bee", "XXX bar burbl blah YYY"); # 56
173 my @bee = my @bee = qw(foo bar burbl blah);
174 is("@bee", "foo bar burbl blah"); # 57
176 my (@bim) = my(@bee) = qw(foo bar);
177 is("@bee", "foo bar"); # 58
178 is("@bim", "foo bar"); # 59
180 is("@bee", "foo bar burbl blah"); # 60
182 is("@bee", "XXX bar burbl blah YYY"); # 61
184 is("@bee", "bar burbl blah"); # 62
186 is("@bee", "foo bar burbl blah"); # 63
189 # try the same with our (except that previous values aren't restored)
192 is("@bee", "foo bar burbl blah");
194 our (undef,@bee) = @bee;
195 is("@bee", "bar burbl blah");
197 our @bee = ('XXX',@bee,'YYY');
198 is("@bee", "XXX bar burbl blah YYY");
200 our @bee = our @bee = qw(foo bar burbl blah);
201 is("@bee", "foo bar burbl blah");
203 our (@bim) = our(@bee) = qw(foo bar);
204 is("@bee", "foo bar");
205 is("@bim", "foo bar");
212 # make sure reification behaves
214 sub reify { $_[1] = $t++; print "@_\n"; }
220 # qw() is no longer a runtime split, it's compiletime.
221 is (qw(foo bar snorfle)[2], 'snorfle');
223 @ary = (12,23,34,45,56);
227 is(push(@ary,56), 4);
228 is(unshift(@ary,12), 5);
234 # bugid #15439 - clearing an array calls destructors which may try
235 # to modify the array - caused 'Attempt to free unreferenced scalar'
239 sub X::DESTROY { @a = () }
240 @a = (bless {}, q{X});
249 # Test negative and funky indices.
269 like($@, qr/Modification of non-creatable array value attempted, subscript -1/, "\$a[-1] = 0");
275 is ($$ref, undef, "\$# on freed array is undef");
277 local $SIG{__WARN__} = sub {push @warn, "@_"};
279 is (scalar @warn, 1);
280 like ($warn[0], qr/^Attempt to set length of freed array/);
285 # Need a new statement to make it go out of scope
287 test_arylen (do {my @a; \$#a});
293 my $outer = \$#array;
295 is (scalar @array, 0);
299 is (scalar @array, 4);
309 is (scalar @array, 0);
312 is (scalar @$ref, 7);
315 is (scalar @array, 0);
320 is (scalar @array, 7);
323 is ($$inner, undef, "orphaned $#foo is always undef");
325 is (scalar @array, 7);
330 is (scalar @array, 7);
333 $$inner = 503; # Bang!
335 is (scalar @array, 7);
365 # Bug #37350 -- once more with a global
379 # more tests for AASSIGN_COMMON
382 our($x,$y,$z) = (1..3);
383 our($y,$z) = ($x,$y);
384 is("$x $y $z", "1 1 2");
387 our($x,$y,$z) = (1..3);
388 (our $y, our $z) = ($x,$y);
389 is("$x $y $z", "1 1 2");
392 # AASSIGN_COMMON detection with logical operators
394 our($x,$y,$z) = (1..3);
395 (our $y, our $z) = $true && ($x,$y);
396 is("$x $y $z", "1 1 2");
401 my $x = get_x(); my %x = %$x; sub get_x { %x=(1..4); return \%x };
403 join(" ", map +($_,$x{$_}), sort keys %x), "1 2 3 4",
404 'bug 70171 (self-assignment via my %x = %$x)'
406 my $y = get_y(); my @y = @$y; sub get_y { @y=(1..4); return \@y };
409 'bug 70171 (self-assignment via my @x = @$x)'
413 # [perl #70171], [perl #82110]
417 my @a = @$ra; # common assignment on 2nd attempt
418 my %h = %$rh; # common assignment on 2nd attempt
420 %h = qw(a 1 b 2 c 3 d 4);
423 goto again unless $i++;
426 'bug 70171 (self-assignment via my @x = @$x) - goto variant'
429 join(" ", map +($_,$h{$_}), sort keys %h), "a 1 b 2 c 3 d 4",
430 'bug 70171 (self-assignment via my %x = %$x) - goto variant'
435 *trit = *scile; $trit[0];
436 ok(1, 'aelem_fast on a nonexistent array does not crash');
439 sub A::DESTROY { $::ra = 0 }
440 $::ra = [ bless [], 'A' ];
442 pass 'no crash when freeing array that is being undeffed';
443 $::ra = [ bless [], 'A' ];
445 pass 'no crash when freeing array that is being cleared';
447 # [perl #85670] Copying magic to elements
449 skip "no Scalar::Util::weaken on miniperl", 1, if is_miniperl;
450 require Scalar::Util;
452 Scalar::Util::weaken ($a = \@ISA);
454 Scalar::Util::weaken ($a = \$ISA[0]);
455 ::is @ISA, 1, 'backref magic is not copied to elements';
461 $ISA[0] = qw(Sphare);
463 sub Sphare::pling { 'pling' }
465 ::is eval { pling peen }, 'pling',
466 'arylen_p magic does not stop isa magic from being copied';
469 # Test that &PL_sv_undef is not special in arrays
472 'exists returns true for &PL_sv_undef elem [perl #7508]';
473 is \$_[0], \undef, 'undef preserves identity in array [perl #109726]';
475 # and that padav also knows how to handle the resulting NULLs
476 @_ = sub { my @a; $a[1]=1; @a }->();
477 is join (" ", map $_//"undef", @_), "undef 1",
478 'returning my @a with nonexistent elements';
485 is $plink[0], 2, '@_ alias to nonexistent elem within array';
487 is $plink[1], 3, '@_ alias to nonexistent neg index within array';
488 is $_[2], undef, 'reading alias to negative index past beginning';
490 like $@, qr/Modification of non-creatable array value attempted, (?x:
492 'error when setting alias to negative index past beginning';
493 is $_[3], undef, 'reading alias to -1 elem of empty array';
495 like $@, qr/Modification of non-creatable array value attempted, (?x:
497 'error when setting alias to -1 elem of empty array';
498 }->($plink[0], $plink[-2], $plink[-5], $plunk[-1]);
503 pass "no assertion failure after assigning ref to arylen when ary is gone";
505 "We're included by lib/Tie/Array/std.t so we need to return something true";