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

Hi, I am a new perl learner. I am finding that the most effective way to learn is to look at scripts that others have written. When I open scripts in editors such as geany, there is syntax highlighting that helps me understand the structure of the program somewhat. I would like to take this a bit further. Is there a way I can just pull out certain bits and pieces of the program - say just the blue-coded structure, and not the variables. This would help me visualize the skeleton of the program without distracting elements and would help me build up the basics bit by bit. Another related question is are you aware of some tool that would take the any perl program and enable me to view the program as a flowchart to see how it has been written and learn from it?
  • Comment on Visualizing the skeleton of a perl code

Replies are listed 'Best First'.
Re: Visualizing the skeleton of a perl code
by Anonymous Monk on Feb 24, 2012 at 23:58 UTC
Re: Visualizing the skeleton of a perl code
by LanX (Saint) on Feb 24, 2012 at 22:16 UTC
    Hmm I'm not sure if hiding variables really helps, but

  • you could use perltidy to produce highlighted code (html), and setup the config such that variables (or other structures) have the backgroundcolor. (like JavaFan suggested)

    But be aware that variable-sigils are important for the syntax.

  • Another approach could be to filter out or fold away inner structures by level of indentation.

  • If you are a total beginner activating tooltips when hovering over a command might help.

  • Using B::Deparse is a good tool to transform code into a standard representation, you can also activate extra parens to better understand the precedence rules applied. Don't know much about Geany, but all of this could also be easily achieved using emacs.

    Cheers Rolf

Re: Visualizing the skeleton of a perl code
by chrestomanci (Priest) on Feb 24, 2012 at 21:58 UTC

    By the blue-coded structure I presume you are referring to a part of the perl syntax that your editor is colouring blue. Seeing as I don't know what editor you are using, or how you have configured it, I don't know what sort of syntax you are referring to.

    I have found in the past that if I want to understand the flow of a large perl script that I have not seen before, a good way is often to to run it under the Devel::NYTProf profiler. The report it generates will contain loads of performance information which you can ignore for now, but it will also tell you for each function what other functions called it, and how often, so by reading the report you can get an idea about the flow of the program, and which parts are important, you can also get a clue where the dead code is, as it will not have any calls to it. (Though make sure you allow for error handling code before you remove anything.)

Re: Visualizing the skeleton of a perl code
by Kc12349 (Monk) on Feb 24, 2012 at 21:37 UTC
    You might want to take a look at Padre, which is a IDE built specifically for Perl.
Re: Visualizing the skeleton of a perl code
by JavaFan (Canon) on Feb 24, 2012 at 21:20 UTC
    Is there a way I can just pull out certain bits and pieces of the program - say just the blue-coded structure, and not the variables.
    Well, you can configure your editor so any non-blue colour is the same colour as your background colour. Or you write your own parser (or modify an existing one)...
    Another related question is are you aware of some tool that would take the any perl program and enable me to view the program as a flowchart to see how it has been written and learn from it?
    Flowcarts? Sorry, Perl didn't exist in the '70s.