Brian Ingerson wrote:
>
> I've tracked this down to a bug in Perl:
[...]
> > perl -066 -e 'BEGIN {local $/ = "7"} print $/' | hexdump
> 0000000 0a00
> 0000001
In fact, this can be simplified : perl doesn't set $/ at
compile-time.
$ perl -066 -e 'BEGIN{print"<$/>"}print"<$/>"'
<
><6>
The patch below should cure it :
(a late followup to patch #12027 by Hugo)
Change 18015 by rgs@rgs-home on 2002/10/12 20:22:37
The -0 command-line switch wasn't setting $/ at compile-time.
Move the initialization of $/ just after switch parsing
(it was done after yyparse().)
Affected files ...
.... //depot/perl/perl.c#454 edit
.... //depot/perl/t/run/switches.t#6 edit
Differences ...
==== //depot/perl/perl.c#454 (text) ====
@@ -1339,6 +1339,7 @@
}
}
switch_end:
+ sv_setsv(get_sv("/", TRUE), PL_rs);
if (
#ifndef SECURE_INTERNAL_GETENV
@@ -1538,12 +1539,6 @@
PL_e_script = Nullsv;
}
-/*
- Not sure that this is still the right place to do this now that we
- no longer use PL_nrs. HVDS 2001/09/09
-*/
- sv_setsv(get_sv("/", TRUE), PL_rs);
-
if (PL_do_undump)
my_unexec();
==== //depot/perl/t/run/switches.t#6 (text) ====
@@ -9,7 +9,7 @@
require "./test.pl";
-plan(tests => 19);
+plan(tests => 20);
# due to a bug in VMS's piping which makes it impossible for runperl()
# to emulate echo -n (ie. stdin always winds up with a newline), these
@@ -64,6 +64,12 @@
);
is( $r, 'abc-def--ghi-jkl-mno--pq-/', '-0777 (slurp mode)' );
+$r = runperl(
+ switches => [ '-066' ],
+ prog => 'BEGIN { print "($/)" } print "[$/]"',
+);
+is( $r, "(\066)[\066]", '$/ set at compile-time' );
+
# Tests for -c
my $filename = 'swctest.tmp';