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

I almost hesitate to ask this question, but I am curious.
I'm involved in a massive recoding project and am slightly concerned that when all is said and done I may (due to human idiocy, ie I found out at 7:30 tonight that it isnt Thursday) leave out a critical scalar somewhere in the process.
Sadly because it is a recode of only part of the system, I cannot change some of the scalar names that I don't find intuitive and have a hard time remembering them (ie. $value1 and $input_type, would be in my code $value_of_object_class and $type_of_object_in_use) admitedly my names are rather long, but they say something about themselves.

If I forget about something like $session_id or any of the around 20 other important scalars and close out without recording them into the database (along with the other scalars in use of lesser importance), I will probably have to recode some good sized chunks of my code. So, bringing me finally to the question I have, does anyone know of a program to run against two perl programs that verifies that one file is using all of the scalars of another, or is able to check on idiotic implementation? I'm thinkin no, that is what the human brain is for, but you guys have been cruisin the perl scene far far longer then I so; I toss this your way.
The best idea I've got (and am currently using) goes a little something like this

#!/bin/bash cat file.pl |grep $ |unique|sort
Admittedly that is entirely unperl like, but thats what I have got, thoughts anyone?

jcpunk
all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)

Replies are listed 'Best First'.
Re: parser / find / implementation thingy?
by davido (Cardinal) on Dec 18, 2003 at 03:05 UTC
    Well, you may be in luck. There's that old expression, "Only perl can parse Perl." And it happens that there's a B:: module that might help you out.

    B::Xref

    Here's how you use it:

    perl -MO=Xref source1.pl >source1.xref

    By doing that, you'll now have a file, "source1.xref", containing a list of all of the symols used in your source code.

    From there, you could do that with any number of programs, and quickly write a little script that compares the symbols found in each crossref file, to alert you to symbols that don't appear in all files.

    Even if you don't bother with writing a comparison/alert script, the B::Xref module is probably a good solution since it organizes the symbols by package and subroutine for quick visual comparison.


    Dave

      Dave, you rock!
      Thanks a ton!

      jcpunk
      all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)
Re: parser / find / implementation thingy?
by delirium (Chaplain) on Dec 18, 2003 at 12:31 UTC
    While you're recoding, don't forget about handy references:

    { my $value_of_object_class = \$value1; my $type_of_object_in_use = \$input_type; if ($$type_of_object_in_use eq 'potato') { ## Do stuff with potato } ## do more stuff }