I'm working on a module for parsing and extracting data out of ELF (Executable and Linkable Format) files which I intend to put on CPAN shortly. An ELF file contains a couple of important tables whose entries describe parts of the file (segments and sections). I have an object which holds on to objects for each of the tables. The tables aren't very interesting, but the table entries are so I want to provide access to the individual entries. Current options look like this:
use warnings;
use strict;
use ELF::Reader;
my $elfPath = $ARGV[1];
my $elfFile = ELF::Reader->new(filePath => $elfPath);
# Using index on the segments object
my $segments = $elfFile->GetSegments();
for my $segIndex (0 .. $elfFile->SegmentCount() - 1) {
next if !${$segments}[$segIndex]->FileSize();
print ${$segments}[$segIndex]->Describe(head => 16, tail => 16, wi
+dth => 32)
};
print "\n";
# Using an iterator
my $nextSeg = $elfFile->GetSegmentIter();
while (my $segment = $nextSeg->()) {
next if !$segment->FileSize();
print $segment->Describe(head => 16, tail => 16, width => 32)
}
Prints:
Type: PT_LOAD
Virtual load address: 0x00000000
Memory image size: 0x000129f8
Segment alignment: 0x00000008
00000000: 20040000 00010019 00010069 00010081
000129e8: 000129c8 60200000 000129d0 20000000
Type: PT_LOAD
Virtual load address: 0x00000000
Memory image size: 0x000129f8
Segment alignment: 0x00000008
00000000: 20040000 00010019 00010069 00010081
000129e8: 000129c8 60200000 000129d0 20000000
The question is: should I provide both access techniques, or just one (which?) or something else? There will be a number of different classes that provide similar acessors.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|