XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Because the symbol foo and the coderef are different things. *foo = ... assigns a new coderef to the symbol foo. It doesn't redefine the coderef for the original sub foo, which is kind of like a constant. \&foo takes the address of a constant, not a variable. So it is analogous to \"Hello World" rather than \$some_var_holding_a_string. You can't reassign it any more than you can reassign the address of the string literal "Hello World". Well, almost so. Sub "literals" are more complex than a string. Redefine a string and you get a different string. Redefine a sub and you get a different association between sub name and body. So if you *really*, *really* were set on redefining sub foo itself, you could, but (a) you have to nudge Perl into compiling code at runtime and (b) you will get a warning about redefining things that are not supposed to be redefined:
which outputs
Best, beth Update: added some explanation about difference between sub and string literals. In reply to Re^3: Taking reference to function
by ELISHEVA
|
|