Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Ho wo create single BIG program with all values of variables by parsing a perl program

by dineshbhatta1973 (Initiate)
on Mar 22, 2012 at 08:33 UTC ( [id://960946]=perlquestion: print w/replies, xml ) Need Help??

dineshbhatta1973 has asked for the wisdom of the Perl Monks concerning the following question:

How to create single BIG program with all values of variables by parsing a perl program For e.g. following is a code will loop through 5 times:

#!/usr/bin/perl -w use strict; use warnings; sub myLoop( $ ) { my $a = shift; print "Loop: $a\n"; } my $a = 1; while( $a < 5 ) { myLoop( $a ); $a++; } print "After loop: \$a=$a\n";

I want to create a single BIG program with all the possible VALUES using the above script as input and the single program should contain all the values each time the myLoop() is executed. Is there any CPAN module to achieve this? i need this because this helps for debugging and want to use this program to output in HTML format with each LOOP as "OK" of "NOT OK". This will help in identifying with what input the script failed. The possible output i am looking is:

sub myLoop( 1 ) { my $a = shift; print "Loop: 1\n"; } sub myLoop( 2 ) { my $a = shift; print "Loop: 2\n"; } sub myLoop( 3 ) { my $a = shift; print "Loop: 3\n"; } sub myLoop( 4 ) { my $a = shift; print "Loop: 4\n"; } print "After loop: \$a=5\n";
  • Comment on Ho wo create single BIG program with all values of variables by parsing a perl program
  • Select or Download Code

Replies are listed 'Best First'.
Re: Ho wo create single BIG program with all values of variables by parsing a perl program
by jethro (Monsignor) on Mar 22, 2012 at 12:24 UTC

    Have you looked at the built-in perl debugger. You can print out all lexical variables with the y command, all non-lexials with V or X. With w you can get a message whenever a specific variable changes its value. You can single-step through the code and automatically do something (like y or V) before each prompt with the '<' command.

    Read "perldoc perldebug" and wonder at all the things you can do ;-)

Re: Ho wo create single BIG program with all values of variables by parsing a perl program
by Anonymous Monk on Mar 22, 2012 at 09:08 UTC
    I kinda doubt you really want that, I think you want Devel::TraceCalls or Devel::Trace. I suppose you *could* marry the two, but I don't think anyone has
Re: Ho wo create single BIG program with all values of variables by parsing a perl program
by GrandFather (Saint) on Mar 22, 2012 at 21:42 UTC

    You can't. At least except for trivial and mostly uninteresting scripts it is either not possible or is infeasible. Consider:

    use strict; use warnings; my $count = 1; while ($count < $ARGV[1]) { prn("$count\n"); } sub prn { print $_[0]; }

    how do you deal with the loop limit being $ARGV1?

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://960946]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-19 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found