A Perl Chicken-and-egg problem
Richard Dice
rdice-e+AXbWqSrlAAvxtiuMwx3w at public.gmane.org
Mon Jun 23 15:49:30 UTC 2008
On Sun, Jun 22, 2008 at 5:43 PM, Lennart Sorensen <
lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org> wrote:
> On Sat, Jun 21, 2008 at 02:58:33PM -0400, Richard Dice wrote:
> > print $#{@$a} . "\n";
> > print $#{@{$a->[$#{@$a}]}} . "\n";
> > print $a->[ $#{@$a} ][ $#{@{$a->[ $#{@$a} ]}} ] . "\n";
>
> And that kind of syntax is why I hate perl more and more as I use it.
> Many languages grow on you with use. perl does the opposite since the
> more you learn the more you realize what an ugly inconsistent disaster
> of a language it is. Yuck!
>
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.)
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.
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:
print $a->[-1][-1] . "\n";
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".
Better?
And again, going back to Paul's original question, the following is both
self-consistent and beautifully clean, and was my recommended approach:
foreach my $x ( myobj::files::list(@params) ) {
foreach my $y ( @$x ) {
print "$_\n" foreach @$y;
}
}
Cheers,
- Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20080623/e52a944f/attachment.html>
More information about the Legacy
mailing list