Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Dynamic names

by 7stud (Deacon)
on Nov 16, 2010 at 21:23 UTC ( #871838=note: print w/replies, xml ) Need Help??

in reply to Dynamic names

Just so you know, this code:


doesn't create anything. It uses what's called a "symbolic reference" to look up a subroutine that already exists. A symbolic reference is just a string, and when you try to dereference a string, {}, perl looks up the string in the symbol table, and in this case retrieves the subroutine, &, with that name.

You can use typeglobs to create new entries in the symbol table, for instance:

*Cow::speak = sub {print "mooo\n"}; Cow->speak(); --output:-- mooo

The rest of your post doesn't make any sense to me.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://871838]
[msh210]: perl -e'warn "test$/", "" '
[msh210]: doesn't append anything.
[msh210]: It should say "If the last nonempty element of LIST" or "If the string thus to be printed does not end in a newline""
[msh210]: Am I wrong?
[shmem]: no. You're right.
[msh210]: About time... last time I was right was... I don't even remember when.
[shmem]: perl -e 'warn "test$/", ^@^ '
[Eily]: well, at least it's right about warn doing the same thing as die :)
[shmem]: same with undef as last element
[msh210]: oh, good point. It's the best kind of correct

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (19)
As of 2017-04-24 12:41 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (439 votes). Check out past polls.