in reply to Re^5: How to safely use $_ in a library function?
in thread How to safely use $_ in a library function?
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: How to safely use $_ in a library function?
by tobyink (Canon) on Sep 19, 2013 at 07:10 UTC | |
by Athanasius (Archbishop) on Sep 19, 2013 at 07:43 UTC | |
by tobyink (Canon) on Sep 19, 2013 at 08:16 UTC | |
by Athanasius (Archbishop) on Sep 19, 2013 at 09:31 UTC |