summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@efn.org>2002-03-04 08:24:32 -0800
committerJarkko Hietaniemi <jhi@iki.fi>2002-03-06 00:34:32 +0000
commit4e3399f9b267135d193509ba5240514af04e9fec (patch)
treee1cbf712891072ead87a2bc38d7f8dcdfc112774
parentfa09c185cf93a599dc0290b9ee4ba0149df70363 (diff)
downloadperl-4e3399f9b267135d193509ba5240514af04e9fec.tar.gz
Re: [PATCH] Re: [ID 20000922.001] Implicit comparison to $. not performed before filehandle read
Message-ID: <ABBh8gzkgezX092yn@efn.org> p4raw-id: //depot/perl@15054
-rw-r--r--op.h1
-rw-r--r--pp_ctl.c33
-rwxr-xr-xt/op/flip.t34
3 files changed, 57 insertions, 11 deletions
diff --git a/op.h b/op.h
index 604eaa3b7e..1cbacb34e9 100644
--- a/op.h
+++ b/op.h
@@ -105,6 +105,7 @@ Deprecated. Use C<GIMME_V> instead.
/* On pushre, re is /\s+/ imp. by split " " */
/* On regcomp, "use re 'eval'" was in scope */
/* On OP_READLINE, was <$filehandle> */
+ /* On RV2[SG]V, don't create GV--in defined()*/
/* old names; don't use in new code, but don't break them, either */
#define OPf_LIST OPf_WANT_LIST
diff --git a/pp_ctl.c b/pp_ctl.c
index eb1394950f..81a96de1c4 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -896,13 +896,16 @@ PP(pp_flip)
else {
dTOPss;
SV *targ = PAD_SV(PL_op->op_targ);
- int flip;
+ int flip = 0;
if (PL_op->op_private & OPpFLIP_LINENUM) {
- struct io *gp_io;
- flip = PL_last_in_gv
- && (gp_io = GvIO(PL_last_in_gv))
- && SvIV(sv) == (IV)IoLINES(gp_io);
+ if (GvIO(PL_last_in_gv)) {
+ flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
+ }
+ else {
+ GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
+ if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv));
+ }
} else {
flip = SvTRUE(sv);
}
@@ -980,11 +983,23 @@ PP(pp_flop)
else {
dTOPss;
SV *targ = PAD_SV(cUNOP->op_first->op_targ);
+ int flop = 0;
sv_inc(targ);
- if ((PL_op->op_private & OPpFLIP_LINENUM)
- ? (GvIO(PL_last_in_gv)
- && SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv)))
- : SvTRUE(sv) ) {
+
+ if (PL_op->op_private & OPpFLIP_LINENUM) {
+ if (GvIO(PL_last_in_gv)) {
+ flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
+ }
+ else {
+ GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
+ if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
+ }
+ }
+ else {
+ flop = SvTRUE(sv);
+ }
+
+ if (flop) {
sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
sv_catpv(targ, "E0");
}
diff --git a/t/op/flip.t b/t/op/flip.t
index d9fa736d54..70666ac658 100755
--- a/t/op/flip.t
+++ b/t/op/flip.t
@@ -4,7 +4,7 @@
chdir 't' if -d 't';
-print "1..10\n";
+print "1..15\n";
@a = (1,2,3,4,5,6,7,8,9,10,11,12);
@@ -19,6 +19,9 @@ if ($y eq '12E0123E0') {print "ok 7\n";} else {print "not ok 7\n";}
@a = ('a','b','c','d','e','f','g');
+{
+local $.;
+
open(of,'harness') or die "Can't open harness: $!";
while (<of>) {
(3 .. 5) && ($foo .= $_);
@@ -34,5 +37,32 @@ if (($x...$x) eq "1") {print "ok 9\n";} else {print "not ok 9\n";}
# coredump reported in bug 20001018.008
readline(UNKNOWN);
$. = 1;
- print "ok 10\n" unless 1 .. 10;
+ $x = 1..10;
+ print "ok 10\n";
+}
+
}
+
+if (!defined $.) { print "ok 11\n" } else { print "not ok 11 # $.\n" }
+
+use warnings;
+my $warn='';
+$SIG{__WARN__} = sub { $warn .= join '', @_ };
+
+if (0..2) { print "ok 12\n" } else { print "not ok 12\n" }
+
+if ($warn =~ /uninitialized/) { print "ok 13\n" } else { print "not ok 13\n" }
+$warn = '';
+
+$x = "foo".."bar";
+
+if ((() = ($warn =~ /isn't numeric/g)) == 2) {
+ print "ok 14\n"
+}
+else {
+ print "not ok 14\n"
+}
+$warn = '';
+
+$. = 15;
+if (15..0) { print "ok 15\n" } else { print "not ok 15\n" }