<br><div class="gmail_quote">On Sun, Jun 22, 2008 at 5:43 PM, Lennart Sorensen <<a href="mailto:lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys@public.gmane.org">lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys@public.gmane.org</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Sat, Jun 21, 2008 at 02:58:33PM -0400, Richard Dice wrote:<br>
> print $#{@$a} . "\n";<br>
> print $#{@{$a->[$#{@$a}]}} . "\n";<br>
> print $a->[ $#{@$a} ][ $#{@{$a->[ $#{@$a} ]}} ] . "\n";<br>
<br>
</div>And that kind of syntax is why I hate perl more and more as I use it.<br>
Many languages grow on you with use. perl does the opposite since the<br>
more you learn the more you realize what an ugly inconsistent disaster<br>
of a language it is. Yuck!<br>
<font color="#888888"></font></blockquote><div><br>You may have noticed that this was the approach to the problem I didn't recommend. This is the trying-to-be-C-with-Perl. (With the added feature that this actually works, while there is no runtime C equivalent without going off into user-created functions for keeping track of the # of members in your linked lists.)<br>
<br>This example is also contrived, so I could demonstrate the syntax layered on itself in my levels (and through multidimensional arrays). I would never say that this was clean. It is however quite self-consistent. The first line shows the base syntax, which isn't so bad. The second line is that syntax indirected through a 2nd level of multidimensional array. The third line is going into the 3rd dimension. Recall that all 3 levels of dimensionality can be sized to unknown at compile-time and are dynamically (and transparently) reallocatable. So, for this much power the syntax is the trade-off. And there are expansion modules that make this cleaner too, if you're interested in using them (like PDL, which is essentially a Matlab-clone
embedded within Perl). Which is how most other languages try to do it.<br>
<br>As this is Perl, there's more than one way to do it -- if what you found particularly objectionable was the last line of those 3 print statements, any sane person (or person who knows Perl and _isn't_ trying to make a contrived example for the sake of demonstrating an aspect of the language syntax) would have written that as:<br>
<br><span style="font-family: courier new,monospace;">print $a->[-1][-1] . "\n";</span><br style="font-family: courier new,monospace;"><br>This is saying "I don't care what the element index # is on any of the higher-level dimensions, just give me the _last_ element".<br>
<br>Better?<br><br>And again, going back to Paul's original question, the following is both self-consistent and beautifully clean, and was my recommended approach:<br><br><span style="font-family: courier new,monospace;">foreach my $x ( </span><span style="font-family: courier new,monospace;">myobj::files::list(@params)</span><span style="font-family: courier new,monospace;"> ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
foreach my $y ( @$x ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> print "$_\n" foreach @$y;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
}</span><br><br>Cheers,<br> - Richard<br><br></div></div>