dcd has asked for the wisdom of the Perl Monks concerning the following question:
perl5 reports this error as$foo = "x"; &mod($foo); for ($x = 0; $x < 3; $x++) { &mod("a"); } sub mod { print "before: $_[0]"; $_[0] = "m"; print " after: $_[0]\n"; }
Short of doing an eval { } like:Modification of a read-only value attempted...
to try to modify to the constant ahead of time, what other ways does perl provide detect that a parameter to a sub is a constant? I've seen that Devel::Peek can report that the flags of a variable are READONLY.eval { $_[0] .= '' }; if ($@ =~ /Modification of a read-only value attempted/) {
Does a module that returns the FLAGS exist?$ perl -MDevel::Peek -le 'Dump("hello")' SV = PV(0x8121a3c) at 0x812b36c REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x812f498 "hello"\0 CUR = 5 LEN = 6
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Detecting constant arguments passed to subroutines
by japhy (Canon) on May 17, 2001 at 00:42 UTC | |
by dcd (Scribe) on May 17, 2001 at 01:24 UTC | |
by dcd (Scribe) on May 17, 2001 at 01:39 UTC | |
by japhy (Canon) on May 17, 2001 at 01:44 UTC | |
by chipmunk (Parson) on May 17, 2001 at 01:43 UTC | |
by dcd (Scribe) on May 17, 2001 at 10:32 UTC | |
by dcd (Scribe) on May 29, 2001 at 10:30 UTC | |
by Anonymous Monk on Sep 14, 2005 at 00:24 UTC | |
by Anonymous Monk on May 17, 2001 at 01:02 UTC |