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:
<br><br><div style="margin-left: 40px; font-family: courier new,monospace; font-weight: bold;">%object_type1 = (<br></div>
<div style="margin-left: 80px; font-family: courier new,monospace; font-weight: bold;">
<div style="margin-left: 40px;">id1 => { fs => $filespec, cl => $changelist, bg => $bug_no },<br>id2 => { fs => $filespec, cl => $changelist, bg => $bug_no },<br>id3 => { fs => $filespec, cl => $changelist, bg => $bug_no },
<br>id4 => { fs => $filespec, cl => $changelist, bg => $bug_no },<br>id5 => { fs => $filespec, cl => $changelist, bg => $bug_no },<br>id6 => { fs => $filespec, cl => $changelist, bg => $bug_no },
<br>
</div>
<div style="margin-left: 40px;">... <br>
</div>);</div><br>The 'id' can be any unique value you'd like of course... then you can access (get or set) it like this:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace; font-weight: bold;">
<span style="font-weight: bold;"><span style="font-weight: bold;"># retrieve a value</span><br></span>my $changelist = $</span>object_type<span style="font-family: courier new,monospace; font-weight: bold;">1{id2}->{cl};
<br><br># set a value<br style="font-family: courier new,monospace; font-weight: bold;"></span><span style="font-family: courier new,monospace; font-weight: bold;">$</span>object_type<span style="font-family: courier new,monospace; font-weight: bold;">
1{id5}->{bg} = $new_bug;<br><br># create a new record<br></span><span style="font-family: courier new,monospace; font-weight: bold;">$</span>object_type<span style="font-family: courier new,monospace; font-weight: bold;">
1{id213} = { </span>fs => $filespec, cl => $changelist, bg => $bug_no };</div><br>...which is pretty efficient, and, I think, straightforward to use. Alternatively you could opt to use anonymous arrays and access them by index.
<br><br><span style="text-decoration: underline;">BUT</span> if you want (or need) to optimize this process (i.e. avoid shelling-out) you might either try the <span style="font-weight: bold;">Inline </span>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
<span style="font-style: italic;">Perforce</span> you could avoid reinventing the wheel and just use something in the <span style="font-weight: bold;">P4</span> namespace from CPAN. Like this guy: <a href="http://search.cpan.org/%7Esmee/P4-3.5313/P4.pm">
http://search.cpan.org/~smee/P4-3.5313/P4.pm</a>.<br><br><br>Hope that helps,<br>Montgomery<br><br><br><div><span class="gmail_quote">On 9/14/07, <b class="gmail_sendername"><a href="mailto:tmcd@panix.com">tmcd@panix.com</a>
</b> <<a href="mailto:tmcd@panix.com">tmcd@panix.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Thu, 13 Sep 2007, Montgomery Conner <
<a href="mailto:montgomery.conner@gmail.com">montgomery.conner@gmail.com</a>> wrote:<br>> If you don't require encapsulation the easiest (and most efficient)<br>> solution would be to forgo building an object to hold this data:
<br>> there would be no point and there is a semi-trivial amount of<br>> overhead in doing so.<br><br>Micro-optimization leads to micro-results. What's going to dominate<br>the runtime of this program is the many many `...` and
<br>open(IN, "...|") calls to external programs.<br><br>> You could use an array instead.<br><br>The three types of objects:<br>- Filespecs like //depot/dev/foo/bar.java#3<br> That's a dead giveaway that it's Perforce.
<br>- Changelist numbers like 67890<br>- Bug numbers like 12345<br><br>A filespec is associated with a changelist. A changelist may be<br>associated with a bug. I have to do system("p4 ...") to find out what<br>
objects exist and their associations. I need to be able to query<br>whether I've dealt with an object before, so lookup must be efficient.<br>There's different data that I want to store with each object type.<br>
<br>Filespecs obviously wouldn't work as array indices, and searching<br>array values would be ugly to work with. The changelist numbers and<br>bug numbers could work as arrays, but I was thinking of hashes anyway.<br>
<br>--<br>Tim McDaniel; Reply-To: <a href="mailto:tmcd@panix.com">tmcd@panix.com</a><br>_______________________________________________<br>Austin mailing list<br><a href="mailto:Austin@pm.org">Austin@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/austin">
http://mail.pm.org/mailman/listinfo/austin</a><br></blockquote></div><br>