From 4c5a6083a6f92a8003034d6119c72e8d828e4613 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Fri, 7 May 1999 08:07:02 +0000 Subject: From: Dan Sugalski Date: Mon, 05 Apr 1999 15:38:42 -0700 Message-Id: <3.0.6.32.19990405153842.0367b650@ous.edu> Subject: Re: chomp fails with $/ in fixed-length record mode -- From: Roderick Schertler Date: Tue, 06 Apr 1999 21:11:37 -0400 Message-ID: <2795.923447497@eeyore.ibcinc.com> Subject: Re: chomp fails with $/ in fixed-length record mode p4raw-id: //depot/perl@3319 --- doop.c | 2 ++ pod/perlfunc.pod | 4 +++- t/op/chop.t | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doop.c b/doop.c index b93223fc49..ccabba1357 100644 --- a/doop.c +++ b/doop.c @@ -831,6 +831,8 @@ do_chomp(register SV *sv) if (RsSNARF(PL_rs)) return 0; + if (RsRECORD(PL_rs)) + return 0; count = 0; if (SvTYPE(sv) == SVt_PVAV) { register I32 i; diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index c973d0c367..b2231a3a87 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -546,7 +546,9 @@ number of characters removed from all its arguments. It's often used to remove the newline from the end of an input record when you're worried that the final record may be missing its newline. When in paragraph mode (C<$/ = "">), it removes all trailing newlines from the string. -If VARIABLE is omitted, it chomps C<$_>. Example: +When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is +a reference to an integer or the like, see L) chomp() won't +remove anything. If VARIABLE is omitted, it chomps C<$_>. Example: while (<>) { chomp; # avoid \n on last field diff --git a/t/op/chop.t b/t/op/chop.t index 77263ad3ad..6723ca3f1b 100755 --- a/t/op/chop.t +++ b/t/op/chop.t @@ -1,8 +1,6 @@ #!./perl -# $RCSfile: chop.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:40 $ - -print "1..28\n"; +print "1..30\n"; # optimized @@ -85,3 +83,9 @@ $_ = "axx"; $/ = "yy"; print chomp() == 0 ? "ok 27\n" : "not ok 27\n"; print $_ eq "axx" ? "ok 28\n" : "not ok 28\n"; + +# This case once mistakenly behaved like paragraph mode. +$_ = "ab\n"; +$/ = \3; +print chomp() == 0 ? "ok 29\n" : "not ok 29\n"; +print $_ eq "ab\n" ? "ok 30\n" : "not ok 30\n"; -- cgit v1.2.1