1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require "./test.pl";
6}
7
8plan(14);
9
10@a = (1,2,3,4,5,6,7,8,9,10,11,12);
11@b = ();
12while ($_ = shift(@a)) {
13    if ($x = /4/../8/) { $z = $x; push @b, $x + 0; }
14    $y .= /1/../2/;
15}
16is(join("*", @b), "1*2*3*4*5");
17
18is($z, '5E0');
19
20is($y, '12E0123E0');
21
22@a = ('a','b','c','d','e','f','g');
23
24{
25local $.;
26
27open(of,'harness') or die "Can't open harness: $!";
28while (<of>) {
29    (3 .. 5) && ($foo .= $_);
30}
31$x = ($foo =~ y/\n/\n/);
32
33is($x, 3);
34
35$x = 3.14;
36ok(($x...$x) eq "1");
37
38{
39    # coredump reported in bug 20001018.008 (#4474)
40    readline(UNKNOWN);
41    $. = 1;
42    $x = 1..10;
43    ok(1);
44}
45
46}
47
48ok(!defined $.);
49
50use warnings;
51my $warn='';
52$SIG{__WARN__} = sub { $warn .= join '', @_ };
53
54ok(scalar(0..2));
55
56like($warn, qr/uninitialized/);
57$warn = '';
58
59$x = "foo".."bar";
60
61ok((() = ($warn =~ /isn't numeric/g)) == 2);
62$warn = '';
63
64$. = 15;
65ok(scalar(15..0));
66
67push @_, \scalar(0..0) for 1,2;
68isnt $_[0], $_[1], '\scalar($a..$b) gives a different scalar each time';
69
70# This evil little example from ticket #122829 abused the fact that each
71# recursion level maintained its own flip-flip state.  The following com-
72# ment describes how it *used* to work.
73
74# This routine maintains multiple flip-flop states, each with its own
75# numeric ID, starting from 1.  Pass the ID as the argument.
76sub f {
77    my $depth = shift() - 1;
78    return f($depth) if $depth;
79    return /3/../5/;
80}
81{
82    my $accumulator;
83    for(1..20) {
84        if (f(1)) {
85            my $outer = $_;
86            for(1..10){
87                $accumulator .= "$outer $_\n" if f(2);
88            }
89        }
90    }
91    is $accumulator, <<EOT, 'recursion shares state';
923 1
933 2
943 3
953 4
963 5
9713 1
9813 2
9913 3
10013 4
10113 5
102EOT
103}
104
105# Void context gives parenthesized lhs scalar context
106no warnings 'void';
107sub c { $context = qw[ void scalar list ][wantarray + defined wantarray] }
108(c())x34;
109is $context, 'scalar', '(...)x... in void context';
110