From: Steve Grazzini Date: Fri, 6 Jun 2003 01:42:59 +0000 (-0400) Subject: Re: nitpick with \(0..2) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb53bbb20d623d0dbe701aa5d8875b725debcd99;p=p5sagit%2Fp5-mst-13.2.git Re: nitpick with \(0..2) Message-ID: <20030606054259.GA30249@grazzini.net> p4raw-id: //depot/perl@19729 --- diff --git a/op.c b/op.c index ad0ed55..a095fb9 100644 --- a/op.c +++ b/op.c @@ -2009,6 +2009,8 @@ Perl_gen_constant_list(pTHX_ register OP *o) o->op_type = OP_RV2AV; o->op_ppaddr = PL_ppaddr[OP_RV2AV]; + o->op_flags &= ~OPf_REF; /* treat \(1..2) like an ordinary list */ + o->op_flags |= OPf_PARENS; /* and flatten \(1..2,3) */ o->op_seq = 0; /* needs to be revisited in peep() */ curop = ((UNOP*)o)->op_first; ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--)); diff --git a/pod/perlop.pod b/pod/perlop.pod index 6bc66d2..1550660 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -418,10 +418,10 @@ Using "or" for assignment is unlikely to do what you want; see below. =head2 Range Operators Binary ".." is the range operator, which is really two different -operators depending on the context. In list context, it returns an +operators depending on the context. In list context, it returns a list of values counting (up by ones) from the left value to the right value. If the left value is greater than the right value then it -returns the empty array. The range operator is useful for writing +returns the empty list. The range operator is useful for writing C loops and for doing slice operations on arrays. In the current implementation, no temporary array is created when the range operator is used as the expression in C loops, but older diff --git a/t/op/ref.t b/t/op/ref.t index b29dcb7..d4c290e 100755 --- a/t/op/ref.t +++ b/t/op/ref.t @@ -200,14 +200,14 @@ foo WHATEVER "ok 38\n"; # test the \(@foo) construct # package main; -@foo = (1,2,3); +@foo = \(1..3); @bar = \(@foo); @baz = \(1,@foo,@bar); print @bar == 3 ? "ok 39\n" : "not ok 39\n"; print grep(ref($_), @bar) == 3 ? "ok 40\n" : "not ok 40\n"; print @baz == 3 ? "ok 41\n" : "not ok 41\n"; -my(@fuu) = (1,2,3); +my(@fuu) = \(1..2,3); my(@baa) = \(@fuu); my(@bzz) = \(1,@fuu,@baa); print @baa == 3 ? "ok 42\n" : "not ok 42\n";