[27221] in Perl-Users-Digest
Perl-Users Digest, Issue: 9017 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 4 09:05:53 2006
Date: Sat, 4 Mar 2006 06:05:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 4 Mar 2006 Volume: 10 Number: 9017
Today's topics:
Re: A Problem With GD <markem@airmail.net>
Emulating Generators: Iterators for Lists (Newbie) <vtatila@mail.student.oulu.fi>
Smart::Comments overwritting? <kirby@lkjh.wanadoo.co.uk>
Re: Smart::Comments overwritting? <karlheinz.weindl@arcor.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 04 Mar 2006 00:21:24 -0600
From: Mark Manning <markem@airmail.net>
Subject: Re: A Problem With GD
Message-Id: <120iccvjpdp1i19@corp.supernews.com>
Uri Guttman wrote:
> finally we can invoke godwin's law and end this stupid thread. we all
> agree manning is an arrogant ass who will never get clpm or the larger
> perl community (especially cpan) nor will he ever understand api
> design. so stop responding to him as godwin's law implies. he seems to
> come back every couple of days and blather so give it a rest and maybe
> he will quietly slink away.
>
> amazing how that law works and how this jerk was totally anticipated by
> it.
>
> uri
>
Actually, that is exactly how I have felt about many of the responses here. But
I have to admit that whoever that warrylall(?) person is is a bit too far out
there for even me.
I will agree to end the thread if everyone else also agrees to it as well. What
do you all say? Yea or nay? That is all that needs to be posted.
------------------------------
Date: Sat, 4 Mar 2006 14:17:41 +0200
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Emulating Generators: Iterators for Lists (Newbie)
Message-Id: <duc0hg$ef4$1@news.oulu.fi>
Hi,
I've been asking a number of pretty generic but newbie questions on
achieving various things in Perl. Here's yet another one. I checked the faq
in perldoc but haven't Googled the archives yet:
What would be a good way to do an iterator for a sequence of values to be
returned, also called a generator, in Perl? That is for a sub-routine
returning a list of values in list context, have it return each element of
the list in scalar context followed by undef. For an analogy, you could
think of each in scalar context Vs. the list returned by keys. Iterators
would save a lot of memory and might be faster, too, if you'll need to
allocate huge lists. Not to mention infinite sequences of which you'd like
to iterate to some finite length determined at runtime. I think some Perl
primitives, such as a list of values generated by the range operator for a
foreach loop, are already optimized for memory efficiency. Python has the
Xrange construct, as well.
One choice that came to mind very first would be to have a block around a
sub-routine, and declare the state you need to maintain between sub calls
for generating the next value, in this block. By refering to the outerblock
in the inner, the variables in the outer are kept alive as long as the
program itself, kind of like static variables in C. The trouble I have with
this approach is that the contents remain even after n subroutine cals
eating memory. Could one simply undef the array or hash in question once the
sub hits the end of the list it's generating? I suppose so but havent'
tested it yet.
Another way of which I'm aware would be to use closures. Return a reference
to a hash of references to anonymous sub-routines. If these routines refer
to constructs in the outer sub-routine block, Perl will keep a set of the
values alive for each hash of subs returned. I feel like I don't really
understand how this works, that is is derived from Perl's scoping rules, but
I just know that this is what happens and have used it myself. A slight
niggle I have with the closure approach is that the syntax is a bit querky
and neither looks like a basic method or subroutine calle, because you'll
have to index to a hash and derefrence the value as a sub. By the hway,
could someone explain closures in detail or point me to good docs on the
Web? A tutorial, down-to-Earth approach would be best, I suppose.
The third choice would be to do the same thing as in the second case but as
an object. YOu could create the data in the constructor, have some kind of
iterator method and the object would be destroyed once there are no
references to it as usual. This is not a simpel sub-routine any more,
however.
Now that I started thinking of this, another problem with returning one
value at a time is that you cannot use this kind of iterator transparently
as a list. Even if a sub handling a list would need to look at only one or
two subsequent list items at once, you'll have to feed it the whole list in
the beginning of the sub-routine call, though you could pass a reference,
however. As to example functions, map needs only one list item at a time
while reduce needs two. Again, are there any good work-arounds for getting
around this limitation of iterators?
I recall reading somewhere that Perl 6 is going to have lazily expanding
lists which might be the answer. But howabout Perl 5, then? Of course you
could feed the sub-routine an iterator in stead but many subs, especially
the built-ins, like to deal with long lists of values.
Any help appreciated as usual. Feel free to point me to earlier threads as
well, though please give as direct links as you can.
--
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
------------------------------
Date: Sat, 04 Mar 2006 09:44:30 +0000
From: Kirby James <kirby@lkjh.wanadoo.co.uk>
Subject: Smart::Comments overwritting?
Message-Id: <dubnhp$qmd$1@news7.svr.pol.co.uk>
Hi,
When I run the following programme (under Windows XP Command Prompt;
ActiveState Perl 5.8.7; Smart::Comments 0.001) I get this output:-
### variable: 1234
: 1234ariable
I has expected the final line to read '### $variable: 1234' - but it
appears that the final ': 1234' has been written starting from the
beginning of the line.
I've looked at the Command Prompt properties - but can't see anything
that would change this behaviour.
Any suggestions appreciated.
Thanks
Kirby
#
# simple.pl
#
use Smart::Comments;
use strict;
my $variable = 1234;
### variable: $variable
### $variable
------------------------------
Date: Sat, 04 Mar 2006 11:30:03 +0100
From: Karlheinz Weindl <karlheinz.weindl@arcor.de>
Subject: Re: Smart::Comments overwritting?
Message-Id: <44096c25$0$13782$9b4e6d93@newsread4.arcor-online.net>
Kirby James schrieb:
> Hi,
>
> When I run the following programme (under Windows XP Command Prompt;
> ActiveState Perl 5.8.7; Smart::Comments 0.001) I get this output:-
>
> ### variable: 1234
>
> : 1234ariable
>
> I has expected the final line to read '### $variable: 1234' - but it
> appears that the final ': 1234' has been written starting from the
> beginning of the line.
>
> I've looked at the Command Prompt properties - but can't see anything
> that would change this behaviour.
>
> Any suggestions appreciated.
>
> Thanks
>
> Kirby
>
>
>
>
> #
> # simple.pl
> #
>
> use Smart::Comments;
> use strict;
>
> my $variable = 1234;
>
> ### variable: $variable
> ### $variable
Seems to me that Smart::Comments does not handle MS line ending
correctly, as it's obviously keeping the CR as part of the string it
processes.
Karlheinz
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9017
***************************************