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 no warnings 'deprecated';
27 $r = join(',', $#foo, @foo);
30 $r = join(',', $#foo, @foo);
33 $r = join(',', $#foo, @foo);
38 $r = join(',', $#bar, @bar);
41 $r = join(',', $#bar, @bar);
44 $r = join(',', $#bar, @bar);
47 $r = join(',', $#bar, @bar);
49 reset 'b' if $^O ne 'VMS';
52 $r = join(',', $#bar, @bar);
55 $r = join(',', $#bar, @bar);
60 $foo = 'now is the time';
61 ok(scalar (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)));
67 ok(!($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))))
68 or diag("$cnt $F1:$F2:$Etc");
70 %foo = ('blurfl','dyick','foo','bar','etc.','etc.');
72 is($bar{'foo'}, 'bar');
74 is($bar{'foo'}, undef);
75 (%bar,$a,$b) = (%foo,'how','now');
76 is($bar{'foo'}, 'bar');
77 is($bar{'how'}, 'now');
78 @bar{keys %foo} = values %foo;
79 is($bar{'foo'}, 'bar');
80 is($bar{'how'}, 'now');
82 @foo = grep(/e/,split(' ','now is the time for all good men to come to'));
83 is(join(' ',@foo), 'the time men come');
85 @foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
86 is(join(' ',@foo), 'now is for all good to to');
88 $foo = join('',('a','b','c','d','e','f')[0..5]);
91 $foo = join('',('a','b','c','d','e','f')[0..1]);
94 $foo = join('',('a','b','c','d','e','f')[6]);
97 @foo = ('a','b','c','d','e','f')[0,2,4];
98 @bar = ('a','b','c','d','e','f')[1,3,5];
99 $foo = join('',(@foo,@bar)[0..5]);
102 $foo = ('a','b','c','d','e','f')[0,2,4];
105 $foo = ('a','b','c','d','e','f')[1];
108 @foo = ( 'foo', 'bar', 'burbl');
110 no warnings 'deprecated';
115 # various AASSIGN_COMMON checks (see newASSIGNOP() in op.c)
120 is("@foo", "foo bar burbl blah"); # 38
123 is("@foo", "bar burbl blah"); # 39
125 @foo = ('XXX',@foo, 'YYY');
126 is("@foo", "XXX bar burbl blah YYY"); # 40
128 @foo = @foo = qw(foo b\a\r bu\\rbl blah);
129 is("@foo", 'foo b\a\r bu\\rbl blah'); # 41
131 @bar = @foo = qw(foo bar); # 42
132 is("@foo", "foo bar");
133 is("@bar", "foo bar"); # 43
135 # try the same with local
136 # XXX tie-stdarray fails the tests involving local, so we use
137 # different variable names to escape the 'tie'
139 @bee = ( 'foo', 'bar', 'burbl', 'blah');
143 is("@bee", "foo bar burbl blah"); # 44
145 local (undef,@bee) = @bee;
146 is("@bee", "bar burbl blah"); # 45
148 local @bee = ('XXX',@bee,'YYY');
149 is("@bee", "XXX bar burbl blah YYY"); # 46
151 local @bee = local(@bee) = qw(foo bar burbl blah);
152 is("@bee", "foo bar burbl blah"); # 47
154 local (@bim) = local(@bee) = qw(foo bar);
155 is("@bee", "foo bar"); # 48
156 is("@bim", "foo bar"); # 49
158 is("@bee", "foo bar burbl blah"); # 50
160 is("@bee", "XXX bar burbl blah YYY"); # 51
162 is("@bee", "bar burbl blah"); # 52
164 is("@bee", "foo bar burbl blah"); # 53
167 # try the same with my
170 is("@bee", "foo bar burbl blah"); # 54
172 my (undef,@bee) = @bee;
173 is("@bee", "bar burbl blah"); # 55
175 my @bee = ('XXX',@bee,'YYY');
176 is("@bee", "XXX bar burbl blah YYY"); # 56
178 my @bee = my @bee = qw(foo bar burbl blah);
179 is("@bee", "foo bar burbl blah"); # 57
181 my (@bim) = my(@bee) = qw(foo bar);
182 is("@bee", "foo bar"); # 58
183 is("@bim", "foo bar"); # 59
185 is("@bee", "foo bar burbl blah"); # 60
187 is("@bee", "XXX bar burbl blah YYY"); # 61
189 is("@bee", "bar burbl blah"); # 62
191 is("@bee", "foo bar burbl blah"); # 63
194 # try the same with our (except that previous values aren't restored)
197 is("@bee", "foo bar burbl blah");
199 our (undef,@bee) = @bee;
200 is("@bee", "bar burbl blah");
202 our @bee = ('XXX',@bee,'YYY');
203 is("@bee", "XXX bar burbl blah YYY");
205 our @bee = our @bee = qw(foo bar burbl blah);
206 is("@bee", "foo bar burbl blah");
208 our (@bim) = our(@bee) = qw(foo bar);
209 is("@bee", "foo bar");
210 is("@bim", "foo bar");
217 # make sure reification behaves
219 sub reify { $_[1] = $t++; print "@_\n"; }
225 # qw() is no longer a runtime split, it's compiletime.
226 is (qw(foo bar snorfle)[2], 'snorfle');
228 @ary = (12,23,34,45,56);
232 is(push(@ary,56), 4);
233 is(unshift(@ary,12), 5);
239 # bugid #15439 - clearing an array calls destructors which may try
240 # to modify the array - caused 'Attempt to free unreferenced scalar'
244 sub X::DESTROY { @a = () }
245 @a = (bless {}, q{X});
254 # Test negative and funky indices.
274 like($@, qr/Modification of non-creatable array value attempted, subscript -1/, "\$a[-1] = 0");
280 is ($$ref, undef, "\$# on freed array is undef");
282 local $SIG{__WARN__} = sub {push @warn, "@_"};
284 is (scalar @warn, 1);
285 like ($warn[0], qr/^Attempt to set length of freed array/);
290 # Need a new statement to make it go out of scope
292 test_arylen (do {my @a; \$#a});
298 my $outer = \$#array;
300 is (scalar @array, 0);
304 is (scalar @array, 4);
314 is (scalar @array, 0);
317 is (scalar @$ref, 7);
320 is (scalar @array, 0);
325 is (scalar @array, 7);
328 is ($$inner, undef, "orphaned $#foo is always undef");
330 is (scalar @array, 7);
335 is (scalar @array, 7);
338 $$inner = 503; # Bang!
340 is (scalar @array, 7);
370 # Bug #37350 -- once more with a global
384 # more tests for AASSIGN_COMMON
387 our($x,$y,$z) = (1..3);
388 our($y,$z) = ($x,$y);
389 is("$x $y $z", "1 1 2");
392 our($x,$y,$z) = (1..3);
393 (our $y, our $z) = ($x,$y);
394 is("$x $y $z", "1 1 2");
397 # AASSIGN_COMMON detection with logical operators
399 our($x,$y,$z) = (1..3);
400 (our $y, our $z) = $true && ($x,$y);
401 is("$x $y $z", "1 1 2");
406 my $x = get_x(); my %x = %$x; sub get_x { %x=(1..4); return \%x };
408 join(" ", map +($_,$x{$_}), sort keys %x), "1 2 3 4",
409 'bug 70171 (self-assignment via my %x = %$x)'
411 my $y = get_y(); my @y = @$y; sub get_y { @y=(1..4); return \@y };
414 'bug 70171 (self-assignment via my @x = @$x)'
418 # [perl #70171], [perl #82110]
422 my @a = @$ra; # common assignment on 2nd attempt
423 my %h = %$rh; # common assignment on 2nd attempt
425 %h = qw(a 1 b 2 c 3 d 4);
428 goto again unless $i++;
431 'bug 70171 (self-assignment via my @x = @$x) - goto variant'
434 join(" ", map +($_,$h{$_}), sort keys %h), "a 1 b 2 c 3 d 4",
435 'bug 70171 (self-assignment via my %x = %$x) - goto variant'
440 *trit = *scile; $trit[0];
441 ok(1, 'aelem_fast on a nonexistent array does not crash');
444 sub A::DESTROY { $::ra = 0 }
445 $::ra = [ bless [], 'A' ];
447 pass 'no crash when freeing array that is being undeffed';
448 $::ra = [ bless [], 'A' ];
450 pass 'no crash when freeing array that is being cleared';
452 # [perl #85670] Copying magic to elements
454 skip "no Scalar::Util::weaken on miniperl", 1, if is_miniperl;
455 require Scalar::Util;
457 Scalar::Util::weaken ($a = \@ISA);
459 Scalar::Util::weaken ($a = \$ISA[0]);
460 ::is @ISA, 1, 'backref magic is not copied to elements';
466 $ISA[0] = qw(Sphare);
468 sub Sphare::pling { 'pling' }
470 ::is eval { pling peen }, 'pling',
471 'arylen_p magic does not stop isa magic from being copied';
475 "We're included by lib/Tie/Array/std.t so we need to return something true";