APM: Just need structs

Montgomery Conner montgomery.conner at gmail.com
Fri Sep 14 16:38:35 PDT 2007


Ech, shelling-out is so 20th century!  :^)  Yeah, if you're going to be
shelling-out a lot an an array wouldn't buy you much efficiency.  If you
need random access to the data you can do it most easily with a hash of
(anonymous) hashes like this:

%object_type1 = (
 id1 => { fs => $filespec, cl => $changelist, bg => $bug_no },
id2 => { fs => $filespec, cl => $changelist, bg => $bug_no },
id3 => { fs => $filespec, cl => $changelist, bg => $bug_no },
id4 => { fs => $filespec, cl => $changelist, bg => $bug_no },
id5 => { fs => $filespec, cl => $changelist, bg => $bug_no },
id6 => { fs => $filespec, cl => $changelist, bg => $bug_no },
 ...
);

The 'id' can be any unique value you'd like of course... then you can access
(get or set) it like this:

# retrieve a value
my $changelist = $object_type1{id2}->{cl};

# set a value
$object_type1{id5}->{bg} = $new_bug;

# create a new record
$object_type1{id213} = { fs => $filespec, cl => $changelist, bg => $bug_no
};

...which is pretty efficient, and, I think, straightforward to use.
Alternatively you could opt to use anonymous arrays and access them by
index.

BUT if you want (or need) to optimize this process (i.e. avoid shelling-out)
you might either try the Inline distribution from CPAN (which would allow
you to tie your code into the native language of the objects your dealing
with via an XSub wrapper),  or if this only interacts with Perforce you
could avoid reinventing the wheel and just use something in the P4 namespace
from CPAN. Like this guy:
http://search.cpan.org/~smee/P4-3.5313/P4.pm<http://search.cpan.org/%7Esmee/P4-3.5313/P4.pm>
.


Hope that helps,
Montgomery


On 9/14/07, tmcd at panix.com <tmcd at panix.com> wrote:
>
> On Thu, 13 Sep 2007, Montgomery Conner <montgomery.conner at gmail.com>
> wrote:
> > If you don't require encapsulation the easiest (and most efficient)
> > solution would be to forgo building an object to hold this data:
> > there would be no point and there is a semi-trivial amount of
> > overhead in doing so.
>
> Micro-optimization leads to micro-results.  What's going to dominate
> the runtime of this program is the many many `...` and
> open(IN, "...|") calls to external programs.
>
> > You could use an array instead.
>
> The three types of objects:
> - Filespecs like //depot/dev/foo/bar.java#3
>   That's a dead giveaway that it's Perforce.
> - Changelist numbers like 67890
> - Bug numbers like 12345
>
> A filespec is associated with a changelist.  A changelist may be
> associated with a bug.  I have to do system("p4 ...") to find out what
> objects exist and their associations.  I need to be able to query
> whether I've dealt with an object before, so lookup must be efficient.
> There's different data that I want to store with each object type.
>
> Filespecs obviously wouldn't work as array indices, and searching
> array values would be ugly to work with.  The changelist numbers and
> bug numbers could work as arrays, but I was thinking of hashes anyway.
>
> --
> Tim McDaniel; Reply-To: tmcd at panix.com
> _______________________________________________
> Austin mailing list
> Austin at pm.org
> http://mail.pm.org/mailman/listinfo/austin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/austin/attachments/20070914/fa6e8558/attachment-0009.html 


More information about the Austin mailing list