After looking again at my last comment, it occurred to me that
another way of doing it would be to convert your program into
an object, and store the data as attributes of the object.
Something like this:
package CParsingThingy;
sub new {
my $class=shift;
my $self={};
# you could either do this...
$self->{program}={};
# or this:
# $self->{functions}=[];
# $self->{typedefs}=[];
# $self->{defined_in}={};
# etc.
bless $self, $class;
}
...
sub parse_program {
my $self=shift;
my $source=shift;
my $program=$self->{program};
# and use $program as before.
..
}
# etc.
This has the advantages of not using globals and of
making it easier, if need be, to
have several CParsingThingy's simultaneously. More than once
I have written a program thinking "nah, I don't need no
stinkin' objects for this" and then find myself going back and
giving it an object interface because it makes it so much easier
to package, reuse and extend things.
--ZZamboni
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.