Yes, Internals::SvREADONLY is there all right:
1:35 >perl -E "say for sort keys %Internals::" SvREADONLY SvREFCNT V hv_clear_placeholders 1:35 >
But it doesn’t work for me. A Windows issue, maybe?
Thanks for the information on where to find the Internals package in the source code.
Update: I tried the Internals module, but that doesn’t work (for me, on Windows) either:
#! perl use strict; use warnings; use Internals qw(SetReadWrite); for (qw(literal1 literal2 literal3)) { print "$_\n"; foo('wilma'); } sub foo { SetReadWrite(\$_); $_ = 'fred'; goto &bar; } sub bar { my ($name) = @_; print "foo --> name = $name, \$_ = $_\n"; }
Output:
12:26 >perl 723_SoPW.pl literal1 Modification of a read-only value attempted at 723_SoPW.pl line 15. 12:28 >
Even IsWriteProtected fails:
#! perl use strict; use warnings; use Internals qw(IsWriteProtected); for (qw(literal1 literal2 literal3)) { print "$_\n"; foo('wilma'); } sub foo { if (IsWriteProtected(\$_)) { warn "Can't modify \$_"; } else { $_ = 'fred'; } goto &bar; } sub bar { my ($name) = @_; print "foo --> name = $name, \$_ = $_\n"; }
Output:
12:28 >perl 723_SoPW.pl literal1 Modification of a read-only value attempted at 723_SoPW.pl line 20. 12:36 >
:-(
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^6: How to safely use $_ in a library function?
by Athanasius
in thread How to safely use $_ in a library function?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |