Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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:
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;
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 );
name: x name: x12 name: x12 name: foo
Again - I don't recommend doing this.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://588559]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-01-17 05:41 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (152 votes). Check out past polls.