in reply to Re: Detecting constant arguments passed to subroutines
in thread Detecting constant arguments passed to subroutines

The is_const code doesn't seem to detect undef as a constant, although Devel::Peek reports it as READONLY
perl -w -le 'sub is_const { !eval { ($_[0]) = $_[0]; 1; } } print "undef is ",(is_const(undef)?"":"not")," a constant"' undef is not a constant perl -MDevel::Peek -le 'Dump(undef)' SV = NULL(0x0) at 0x8120d38 REFCNT = 2147483622 FLAGS = (READONLY)

Replies are listed 'Best First'.
Re: Re: Re: Detecting constant arguments passed to subroutines
by dcd (Scribe) on May 17, 2001 at 01:39 UTC
    I just noticed the REFCNT the Devel::Peek::Dump(undef) printed
    That can't be right, can it?
      Perhaps it's that high so that it never "dies"? And the reason it doesn't say undef is constant (from my function) is because undef = $foo is illegal, but (undef) = $foo isn't. Fix:
      sub is_const { defined($_[0]) and !eval { ($_[0]) = $_[0]; 1 } }


      japhy -- Perl and Regex Hacker
      undef is a very popular value! :)