5 @INC = ('.', '../lib');
13 # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
17 is(join('',@ary), '12345');
19 $tmp = $ary[$#ary]; --$#ary;
22 is(join('',@ary), '1234');
25 no warnings 'deprecated';
28 $r = join(',', $#foo, @foo);
31 $r = join(',', $#foo, @foo);
34 $r = join(',', $#foo, @foo);
39 $r = join(',', $#bar, @bar);
42 $r = join(',', $#bar, @bar);
45 $r = join(',', $#bar, @bar);
48 $r = join(',', $#bar, @bar);
50 reset 'b' if $^O ne 'VMS';
53 $r = join(',', $#bar, @bar);
56 $r = join(',', $#bar, @bar);
61 $foo = 'now is the time';
62 ok(scalar (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)));
68 ok(!($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))))
69 or diag("$cnt $F1:$F2:$Etc");
71 %foo = ('blurfl','dyick','foo','bar','etc.','etc.');
73 is($bar{'foo'}, 'bar');
75 is($bar{'foo'}, undef);
76 (%bar,$a,$b) = (%foo,'how','now');
77 is($bar{'foo'}, 'bar');
78 is($bar{'how'}, 'now');
79 @bar{keys %foo} = values %foo;
80 is($bar{'foo'}, 'bar');
81 is($bar{'how'}, 'now');
83 @foo = grep(/e/,split(' ','now is the time for all good men to come to'));
84 is(join(' ',@foo), 'the time men come');
86 @foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
87 is(join(' ',@foo), 'now is for all good to to');
89 $foo = join('',('a','b','c','d','e','f')[0..5]);
92 $foo = join('',('a','b','c','d','e','f')[0..1]);
95 $foo = join('',('a','b','c','d','e','f')[6]);
98 @foo = ('a','b','c','d','e','f')[0,2,4];
99 @bar = ('a','b','c','d','e','f')[1,3,5];
100 $foo = join('',(@foo,@bar)[0..5]);
103 $foo = ('a','b','c','d','e','f')[0,2,4];
106 $foo = ('a','b','c','d','e','f')[1];
109 @foo = ( 'foo', 'bar', 'burbl');
111 no warnings 'deprecated';
116 # various AASSIGN_COMMON checks (see newASSIGNOP() in op.c)
121 is("@foo", "foo bar burbl blah"); # 38
124 is("@foo", "bar burbl blah"); # 39
126 @foo = ('XXX',@foo, 'YYY');
127 is("@foo", "XXX bar burbl blah YYY"); # 40
129 @foo = @foo = qw(foo b\a\r bu\\rbl blah);
130 is("@foo", 'foo b\a\r bu\\rbl blah'); # 41
132 @bar = @foo = qw(foo bar); # 42
133 is("@foo", "foo bar");
134 is("@bar", "foo bar"); # 43
136 # try the same with local
137 # XXX tie-stdarray fails the tests involving local, so we use
138 # different variable names to escape the 'tie'
140 @bee = ( 'foo', 'bar', 'burbl', 'blah');
144 is("@bee", "foo bar burbl blah"); # 44
146 local (undef,@bee) = @bee;
147 is("@bee", "bar burbl blah"); # 45
149 local @bee = ('XXX',@bee,'YYY');
150 is("@bee", "XXX bar burbl blah YYY"); # 46
152 local @bee = local(@bee) = qw(foo bar burbl blah);
153 is("@bee", "foo bar burbl blah"); # 47
155 local (@bim) = local(@bee) = qw(foo bar);
156 is("@bee", "foo bar"); # 48
157 is("@bim", "foo bar"); # 49
159 is("@bee", "foo bar burbl blah"); # 50
161 is("@bee", "XXX bar burbl blah YYY"); # 51
163 is("@bee", "bar burbl blah"); # 52
165 is("@bee", "foo bar burbl blah"); # 53
168 # try the same with my
171 is("@bee", "foo bar burbl blah"); # 54
173 my (undef,@bee) = @bee;
174 is("@bee", "bar burbl blah"); # 55
176 my @bee = ('XXX',@bee,'YYY');
177 is("@bee", "XXX bar burbl blah YYY"); # 56
179 my @bee = my @bee = qw(foo bar burbl blah);
180 is("@bee", "foo bar burbl blah"); # 57
182 my (@bim) = my(@bee) = qw(foo bar);
183 is("@bee", "foo bar"); # 58
184 is("@bim", "foo bar"); # 59
186 is("@bee", "foo bar burbl blah"); # 60
188 is("@bee", "XXX bar burbl blah YYY"); # 61
190 is("@bee", "bar burbl blah"); # 62
192 is("@bee", "foo bar burbl blah"); # 63
195 # try the same with our (except that previous values aren't restored)
198 is("@bee", "foo bar burbl blah");
200 our (undef,@bee) = @bee;
201 is("@bee", "bar burbl blah");
203 our @bee = ('XXX',@bee,'YYY');
204 is("@bee", "XXX bar burbl blah YYY");
206 our @bee = our @bee = qw(foo bar burbl blah);
207 is("@bee", "foo bar burbl blah");
209 our (@bim) = our(@bee) = qw(foo bar);
210 is("@bee", "foo bar");
211 is("@bim", "foo bar");
218 # make sure reification behaves
220 sub reify { $_[1] = $t++; print "@_\n"; }
226 # qw() is no longer a runtime split, it's compiletime.
227 is (qw(foo bar snorfle)[2], 'snorfle');
229 @ary = (12,23,34,45,56);
233 is(push(@ary,56), 4);
234 is(unshift(@ary,12), 5);
240 # bugid #15439 - clearing an array calls destructors which may try
241 # to modify the array - caused 'Attempt to free unreferenced scalar'
245 sub X::DESTROY { @a = () }
246 @a = (bless {}, q{X});
255 # Test negative and funky indices.
275 like($@, qr/Modification of non-creatable array value attempted, subscript -1/, "\$a[-1] = 0");
281 is ($$ref, undef, "\$# on freed array is undef");
283 local $SIG{__WARN__} = sub {push @warn, "@_"};
285 is (scalar @warn, 1);
286 like ($warn[0], qr/^Attempt to set length of freed array/);
291 # Need a new statement to make it go out of scope
293 test_arylen (do {my @a; \$#a});
299 my $outer = \$#array;
301 is (scalar @array, 0);
305 is (scalar @array, 4);
315 is (scalar @array, 0);
318 is (scalar @$ref, 7);
321 is (scalar @array, 0);
326 is (scalar @array, 7);
329 is ($$inner, undef, "orphaned $#foo is always undef");
331 is (scalar @array, 7);
336 is (scalar @array, 7);
339 $$inner = 503; # Bang!
341 is (scalar @array, 7);
371 # Bug #37350 -- once more with a global
385 # more tests for AASSIGN_COMMON
388 our($x,$y,$z) = (1..3);
389 our($y,$z) = ($x,$y);
390 is("$x $y $z", "1 1 2");
393 our($x,$y,$z) = (1..3);
394 (our $y, our $z) = ($x,$y);
395 is("$x $y $z", "1 1 2");
398 # AASSIGN_COMMON detection with logical operators
400 our($x,$y,$z) = (1..3);
401 (our $y, our $z) = $true && ($x,$y);
402 is("$x $y $z", "1 1 2");
407 my $x = get_x(); my %x = %$x; sub get_x { %x=(1..4); return \%x };
409 join(" ", map +($_,$x{$_}), sort keys %x), "1 2 3 4",
410 'bug 70171 (self-assignment via my %x = %$x)'
412 my $y = get_y(); my @y = @$y; sub get_y { @y=(1..4); return \@y };
415 'bug 70171 (self-assignment via my @x = @$x)'
419 # [perl #70171], [perl #82110]
423 my @a = @$ra; # common assignment on 2nd attempt
424 my %h = %$rh; # common assignment on 2nd attempt
426 %h = qw(a 1 b 2 c 3 d 4);
429 goto again unless $i++;
432 'bug 70171 (self-assignment via my @x = @$x) - goto variant'
435 join(" ", map +($_,$h{$_}), sort keys %h), "a 1 b 2 c 3 d 4",
436 'bug 70171 (self-assignment via my %x = %$x) - goto variant'
441 *trit = *scile; $trit[0];
442 ok(1, 'aelem_fast on a nonexistent array does not crash');
444 "We're included by lib/Tie/Array/std.t so we need to return something true";