A Perl Chicken-and-egg problem
Lennart Sorensen
lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Mon Jun 23 16:25:15 UTC 2008
On Mon, Jun 23, 2008 at 11:49:30AM -0400, Richard Dice wrote:
> 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.)
C isn't exactly something one should try to be most of the time.
> 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.
I don't much like arrays. Lists implemented as a proper type in a
language is much nicer.
> 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;
> }
> }
I am still very unhappy about @$x being valid syntax at all.
--
Len Sorensen
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list