CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
parse perl code? wanna get all variables from perl code

 



mrstupid
Novice

Sep 14, 2010, 7:24 AM

Post #1 of 7 (2040 views)
parse perl code? wanna get all variables from perl code Can't Post

hello, all,

I have this program which needs to get variables defined in a piece of Perl code.
Given the complexity of Perl grammar, I found this really hard.
Does anyone know how to make this possible?
I want to read the source code of perl compiler which may give me some help, is lib/B/Deparse.pm wher I should get to start?

lots of thanks!

In Reply To



shawnhcorey
Enthusiast


Sep 14, 2010, 8:48 AM

Post #2 of 7 (2035 views)
Re: [mrstupid] parse perl code? wanna get all variables from perl code [In reply to] Can't Post

Try:

Code
perl -MO=Xref,-r myscript.pl


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


mrstupid
Novice

Sep 14, 2010, 7:07 PM

Post #3 of 7 (2023 views)
Re: [shawnhcorey] parse perl code? wanna get all variables from perl code [In reply to] Can't Post

that's really helpful, thanks!!!


shawnhcorey
Enthusiast


Sep 14, 2010, 7:11 PM

Post #4 of 7 (2020 views)
Re: [mrstupid] parse perl code? wanna get all variables from perl code [In reply to] Can't Post

I forgot to add:

See `perldoc B::Xref`.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


mrstupid
Novice

Sep 14, 2010, 11:07 PM

Post #5 of 7 (2017 views)
Re: [shawnhcorey] parse perl code? wanna get all variables from perl code [In reply to] Can't Post

yes, I am reading it.
Although sometime Xref cannot work properly, like it cannot parse the Object method call properly, I think can solve my problem.
Thanks again!


rovf
Veteran

Sep 15, 2010, 1:10 AM

Post #6 of 7 (2015 views)
Re: [mrstupid] parse perl code? wanna get all variables from perl code [In reply to] Can't Post


Quote
Although sometime Xref cannot work properly


The *general* problem is not solvable anyway, because variable names can also be created at runtime.


shawnhcorey
Enthusiast


Sep 15, 2010, 6:01 AM

Post #7 of 7 (2003 views)
Re: [rovf] parse perl code? wanna get all variables from perl code [In reply to] Can't Post


In Reply To
The *general* problem is not solvable anyway, because variable names can also be created at runtime.


That's generally considered a bad idea. Symbolic references, especially ones created by the user, can get you into trouble. Use a hash instead.

See `perldoc perlref` and search for /Symbolic references/.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives