Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Source filter or PadWalker. Both are ugly

by imp (Priest)
on Dec 08, 2006 at 11:18 UTC ( #588559=note: print w/ replies, xml ) Need Help??


in reply to Source filter or PadWalker. Both are ugly
in thread How to extract the name of a variable?

It didn't seem fair (or fun) to provide a PadWalker example, and not a Filter::Simple one. I don't recommend using either of these approaches, but here is a basic(?) filter implementation: ShownameFilter.pm

package ShownameFilter; use Filter::Simple; FILTER_ONLY code => sub { s{ showname\( ( # Capture 2 (closes second) \s* \\? # References [\$@%*]+ # Scalar, array, hash, glob ( # Capture 1 (closes first) \w* # alphanumeric. Doesn't catch a lot of perl spe +cial vars ) # End capture 1 \s* ) # End capture 2 \) } {showname('$2',$1)}xg; }; 1;
showname.pl
use strict; use warnings; use ShownameFilter; sub showname { my ($name,$value) = @_; print "name: $name\n"; } my ($x, $x12, @foo, %bar); showname($x); showname( $x12 ); showname( \$x12 ); showname( @foo );
Output:
name: x name: x12 name: x12 name: foo
Again - I don't recommend doing this.


Comment on Re: Source filter or PadWalker. Both are ugly
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://588559]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (17)
As of 2014-07-23 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (145 votes), past polls