Mailing List Archive

local $^O = $^O --> undef
 perl -wE 'local $^O = $^O; die "oops" unless defined $^O; say "IT IS
$^O";'

dies because the localized $^O is undef.      Doing local $^O = $^O."";
avoids the problem

(Why would anyone do that ?!?   In a module test I was localizing $^O to
lie about the OS to exercise some OS-specific behavior, using a loop;
one case was to use the actual OS of the cpan smoker, i.e. the original
$^O.)

FWIW,  local $PID = $PID; works (doesn't have this problem), but   local
$^F = $^F; becomes 0.  I haven't tried others.

-Jim
Re: local $^O = $^O --> undef [ In reply to ]
On 27.10.23 00:29, Jim Avera wrote:
>  perl -wE 'local $^O = $^O; die "oops" unless defined $^O; say "IT IS
> $^O";'
>
> dies because the localized $^O is undef.      Doing local $^O = $^O."";
> avoids the problem

See also https://github.com/Perl/perl5/issues/5835.
Re: local $^O = $^O --> undef [ In reply to ]
On 10/26/23 3:29 PM, Jim Avera wrote:
>  perl -wE 'local $^O = $^O; die "oops" unless defined $^O; say "IT IS
> $^O";'
>
> dies because the localized $^O is undef.      Doing local $^O =
> $^O.""; avoids the problem
>
> (Why would anyone do that ?!?   In a module test I was localizing $^O
> to lie about the OS to exercise some OS-specific behavior, using a
> loop; one case was to use the actual OS of the cpan smoker, i.e. the
> original $^O.)
>
> FWIW,  local $PID = $PID; works (doesn't have this problem), but local
> $^F = $^F; becomes 0.  I haven't tried others.
>
> -Jim
>
Yes, this looks like a dup of #5835
<https://github.com/Perl/perl5/issues/5835> as mauke pointed out!