[30378] in Perl-Users-Digest
Perl-Users Digest, Issue: 1621 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 8 18:09:41 2008
Date: Sun, 8 Jun 2008 15:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 8 Jun 2008 Volume: 11 Number: 1621
Today's topics:
Re: FAQ 4.14 How can I compare two dates and find the d (David Combs)
Re: FAQ 4.14 How can I compare two dates and find the d (David Combs)
Re: FAQ 4.47 How do I handle circular lists? (David Combs)
Re: FAQ 4.61 What's the difference between "delete" and <hansmu@xs4all.nl>
Re: FAQ 5.14 How can I translate tildes (~) in a filena <mjcarman@mchsi.com>
Re: FAQ 5.14 How can I translate tildes (~) in a filena <hjp-usenet2@hjp.at>
Re: FAQ 5.38 How do I select a random line from a file? <hjp-usenet2@hjp.at>
Re: FAQ 5.38 How do I select a random line from a file? <danrumney@warpmail.net>
Re: FAQ 5.38 How do I select a random line from a file? <hjp-usenet2@hjp.at>
Re: FAQ 5.5 How can I copy a file? <jurgenex@hotmail.com>
Re: FAQ 5.5 How can I copy a file? <hjp-usenet2@hjp.at>
Re: how to change the date format of all my htmls? <noreply@gunnar.cc>
Re: how to change the date format of all my htmls? <tadmc@seesig.invalid>
How to find memory leak in perl server <shtil@comcast.net>
Re: Order of operations (David Combs)
Re: Performance on Windows: Cygwin is much faster. Why? <hjp-usenet2@hjp.at>
Re: Perl grep and Perl 4 <cwilbur@chromatico.net>
Re: Tk with Thread <slick.users@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 8 Jun 2008 20:49:29 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 4.14 How can I compare two dates and find the difference?
Message-Id: <g2hgkp$o5n$1@reader2.panix.com>
In article <m1prrra3a7.fsf@dot-app.org>,
Sherman Pendley <spamtrap@dot-app.org> wrote:
>Philluminati <Phillip.Ross.Taylor@gmail.com> writes:
>
>> It doesn't matter what reader I use. It is useless junk that is a
>> waste of bandwidth. End of story.
>
>You're welcome to your opinion, but really should get over yourself - it's
>just your opinion, not the "end of story." You're nobody special.
>
>Many of us were here when the FAQ began to be posted, and witnessed first-
>hand the reduction in the number of redundant questions that resulted. You'll
>have a difficult time convincing people who used to see the same question
>asked six times a day in pre-FAQ days, that auto-posting it is a waste.
>
>sherm--
>
>--
>My blog: http://shermspace.blogspot.com
>Cocoa programming in Perl: http://camelbones.sourceforge.net
Not only that, having these things pop up once in a while
gives us all a chance to (re)visit them, and perhaps IMPROVE
them, make them more educational, tutorial, and UP TO DATE
(like if some new perl-feature provides eg an easier way
to attack the same problem -- the faq would be hopefully be
changed to show BOTH techniques.)
In my opinion, these revisit-possibilities contribute a LOT
to the Perl community.
David
------------------------------
Date: Sun, 8 Jun 2008 20:55:47 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 4.14 How can I compare two dates and find the difference?
Message-Id: <g2hh0j$mc$1@reader2.panix.com>
In article <g09snv029d0@news4.newsguy.com>, szr <szrRE@szromanMO.comVE> wrote:
>Philluminati wrote:
>> On May 12, 8:03 am, PerlFAQ Server <br...@stonehenge.com> wrote:
>[...]
>>> These postings aim to reduce the number of repeated questions
>>> as well as allow the community to review and update the answers.
>[...]
>> Honestly, what is the point of posting this?
>
>You quoted the answer to your own question. If you don't want to read
>them (which would be your loss), then skip and move on to what you
>prefer to read.
>
>--
>szr
>
>
And I repeat an earlier comment -- GET YOURSELF A DECENT NEWSREADER,
and with it FOREVER CONSIGN these faq-posts to your own bit-bucket.
Just because YOU don't like something doesn't mean that YOU get
to deprive everyone else of it!
And about "decent newsreaders", the said delete-these-subjects
features are DESIGNED for use by people precicely like you --
so GET ONE AND USE IT, and your life here on clpm will be
far happier.
David
------------------------------
Date: Sun, 8 Jun 2008 21:08:16 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 4.47 How do I handle circular lists?
Message-Id: <g2hho0$pns$1@reader2.panix.com>
In article <437ac873-a0a5-4186-8f3d-fdb7a14d98de@k37g2000hsf.googlegroups.com>,
<sheinrich@my-deja.com> wrote:
>On May 12, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
>> --------------------------------------------------------------------
>>
>> 4.47: How do I handle circular lists?
>>
>> Circular lists could be handled in the traditional fashion with linked
>> lists, or you could just do something like this with an array:
>>
>> unshift(@array, pop(@array)); # the last shall be first
>> push(@array, shift(@array)); # and vice versa
>>
>>
>
>As the modulo operator provides a simple way to address an array in a
>circular fashion, which is maybe not obvious to the less experienced,
>I think it should be mentioned here.
>
>my @Colours = qw( FFFFFF 000000 FFFF00 );
>
>my $asize = @Colours;
>my $index = 0;
>
>for (1..10) {
> print $Colours[$index], "\n";
>
> $index = ++$index % $asize;
>}
>
># or shorter, with an ever growing $index though:
>
>$index = 0;
>
>for (1..10) {
> print $Colours[$index++ % $asize], "\n";
>}
>
>
>steffen
>
Not only for the less-experienced, but for *everyone* -- that
is, if you're doing a *lot* of them. Why?
Because having the one fixed-in-memory array with an index
running back and forth within it involves ZERO garbage-collection
overhead. Allocate the thing once, and it's done.
Now, if the thing has to grow from time to time, then the
push and pop ptrs (indices) (unbalanced) run into each other,
and you have to grow the array, maybe double (or some other function)
its size, do you don't do this growing (eg gc-causing) at every
"push".
In fact, write a simple fcn "verifySizeOk" (ary, desired-next-index
to use) and let it do whatever's needed as the need occurs.
Anyway, pushes are nice, but the gc's can eat you alive.
[of course, probably lists are internally allocated er grown
*already* by some such scheme!]
David
------------------------------
Date: Sun, 08 Jun 2008 21:56:41 +0200
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: FAQ 4.61 What's the difference between "delete" and "undef" with hashes?
Message-Id: <484c397b$0$14352$e4fe514c@news.xs4all.nl>
PerlFAQ Server wrote:
> 4.61: What's the difference between "delete" and "undef" with hashes?
[....]
> exists $hash{'a'} is true (Perl 5 only)
I think "Perl 5 only" here means "only if you use Perl 5.000 or later".
Most of the advice given in the FAQ doesn't work in Perl 4, but people
don't complain, because the readers of this newsgroup all switched to
Perl 5 long ago. So I propose to leave out this "Perl 5 only" note
(here and twice more in the same answer).
-- HansM
------------------------------
Date: Sun, 08 Jun 2008 14:19:00 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: FAQ 5.14 How can I translate tildes (~) in a filename?
Message-Id: <oTR2k.145368$TT4.133805@attbi_s22>
PerlFAQ Server wrote:
> Older versions of Perl require that you have a shell installed that
> groks tildes. Recent perl versions have this feature built in.
Can anyone here quantify "older" and "recent?"
-mjc
------------------------------
Date: Sun, 8 Jun 2008 16:46:37 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.14 How can I translate tildes (~) in a filename?
Message-Id: <slrng4ns6d.boh.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-08 14:19, Michael Carman <mjcarman@mchsi.com> wrote:
> PerlFAQ Server wrote:
>> Older versions of Perl require that you have a shell installed that
>> groks tildes. Recent perl versions have this feature built in.
>
> Can anyone here quantify "older" and "recent?"
I *think* this was changed in perl 5.6.0.
hp
------------------------------
Date: Sun, 8 Jun 2008 15:58:32 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <slrng4npc8.9ut.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-08 00:34, brian d foy <brian.d.foy@gmail.com> wrote:
> In article <484adab2$0$30196$4c368faf@roadrunner.com>, Dan Rumney
><danrumney@warpmail.new> wrote:
>> Peter J. Holzer wrote:
>> > On 2008-06-04 19:03, PerlFAQ Server <brian@stonehenge.com> wrote:
>> >> 5.38: How do I select a random line from a file?
>
>> > If your file is large, and the lines are roughly of equal length,
>> > it is probably preferrable to just do a random seek into the file
>> > and read the line you've hit (by searching backwards and forwards
>> > for $/).
>
>> The problem with that is that the probability of selecting a line
>> becomes a function of that line's length.
That's why I wrote that the lines need to be roughly the same length. I
should have been more precice: "roughly the same length" was meant as
"the difference in length (and hence probability) is smaller than the
skew you can tolerate for your particular application". There is a
simple way to work around that bias (choose another random line if
rand(length($line)) > 1), but that causes a lot of extra seeks, and will
probably be slower than reading the whole file in the first place. You
can improve on this if you know the minimal line length or that the
distribution of line lengths in each block is the same.
>> The algorithm above ensures that the probability of selecting a line is
>> precisely 1/N where N is the total number of lines in the file.
>
> From time to time, I think about how I would solve this problem if I
> actually needed it for something important. That is, not as some
> thought experiment or quote-for-the-sig thing.
>
> Has anyone solved this for something non-trivial?
A long time ago I solved it for a quote-for-the-sig thing.
> Say, for something with huge numbers of lines or large file sizes, or
> where you want to choose several random lines?
The file wasn't huge (a bit over 100kB, IIRC), but reading it from a 20
MB hard disk (or, worse, a 360 kB floppy) caused a noticeable delay.
> The solution that I think about (but have never implemented), is some
> sort of pre-indexing of line endings so you have a list of file
> positions where all the lines line (or start, or whatever). When you
> want a random line, you choose a random element from that list. Open
> the file, seek, and read a line.
That's exactly what I did. An index file with a four-byte offset of the
start of each fortune. When the index file was missing or older than the
fortune file, it was rebuilt by reading through the fortune file
sequentially, calling ftell at the start of each fortune.
> I guess if it really mattered, you'd put every line in a some sort of
> persistence thingy and choose choose a random record without having to
> read a file at all.
I'd call a "persistence thingy" a "file". ;-)
hp
------------------------------
Date: Sun, 08 Jun 2008 13:13:50 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <484c1359$0$4074$4c368faf@roadrunner.com>
comp.llang.perl.moderated wrote:
[snip]
>>> A simplistic solution might me:
>>> my %linePostiion;
>>> $linePostion{$.} = tell($fh) while <$fh>;
>>> Then use %linePosition with a random index to find the file position of
>>> a random line.
>> A tad faster to just index into
>> a simple array of file positions:
>>
>> push @pos, tell($fh) while <$fh>;
>
> Simpler but I made a kneejerk assertion that it's
> faster... just suspect in lots of cases, it will be.
I wasn't sure, so I checked. The code is at the end of the post.
I ran this against a 3.6 MB XML file, 100 times.
Finding random line from c:\dumpdecoder\svc.config.kdc.xml, 100 times
Rate Random Line By Hash Random Line By Array
Random Line By Hash 1.86/s -- -79%
Random Line By Array 8.84/s 375% --
So, it looks like the hash method is, in this case, the faster.
I also ran it against a 412 byte batch file 10000 times.
Finding random line from c:\dumpdecoder\getSnapshot.bat, 10000 times
Rate Random Line By Hash Random Line By Array
Random Line By Hash 3503/s -- -1%
Random Line By Array 3542/s 1% --
As you can see, not much difference in this case.
CODE
----
use strict;
use IO::File;
use Benchmark qw(:all) ;
my $fName = shift;
my $count = shift;
print "Finding random line from $fName, $count times\n";
cmpthese($count, {
'Random Line By Hash' => sub {
my $filename = shift;
my $fh = new IO::File($fName, "r") || die $!;
my %linePostiion;
$linePostiion{$.} = tell($fh) while <$fh>;
$fh->close; },
'Random Line By Array' => sub {
my $filename = shift;
my $fh = new IO::File($fName, "r") || die $!;
my @pos;
push @pos, tell($fh) while <$fh>;
$fh->close;
}
});
------------------------------
Date: Sun, 8 Jun 2008 21:07:31 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <slrng4obfj.e55.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-08 17:13, Dan Rumney <danrumney@warpmail.net> wrote:
> comp.llang.perl.moderated wrote:
> [snip]
>>>> A simplistic solution might me:
>>>> my %linePostiion;
>>>> $linePostion{$.} = tell($fh) while <$fh>;
>>>> Then use %linePosition with a random index to find the file position of
>>>> a random line.
>>> A tad faster to just index into
>>> a simple array of file positions:
>>>
>>> push @pos, tell($fh) while <$fh>;
>>
>> Simpler but I made a kneejerk assertion that it's
>> faster... just suspect in lots of cases, it will be.
>
> I wasn't sure, so I checked. The code is at the end of the post.
> I ran this against a 3.6 MB XML file, 100 times.
>
> Finding random line from c:\dumpdecoder\svc.config.kdc.xml, 100 times
> Rate Random Line By Hash Random Line By Array
> Random Line By Hash 1.86/s -- -79%
> Random Line By Array 8.84/s 375% --
>
> So, it looks like the hash method is, in this case, the faster.
Er ...
8.84/s seems faster to me than 1.86/s.
hp
------------------------------
Date: Sun, 08 Jun 2008 13:28:44 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 5.5 How can I copy a file?
Message-Id: <8fnn44p39k8ib467ifif33k9lbn7shk6dn@4ax.com>
Bill H <bill@ts1000.us> wrote:
>> Use the File::Copy module. It comes with Perl and can do a true copy
>
>What is the advantage of using this over using system("cp $original
>$new_copy"); (or system("copy $original $new_copy"); on windows)? Is
>it faster or is it just "perlish"? Or am I missing something obvious?
system() isn't portable.
File::Copy also avoids forking external processes, although the time
savings are probably pretty irrelevant given the nature of the
operation.
jue
------------------------------
Date: Sun, 8 Jun 2008 16:15:21 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.5 How can I copy a file?
Message-Id: <slrng4nqbp.9ut.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-08 11:01, Bill H <bill@ts1000.us> wrote:
> On Jun 7, 3:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
>> 5.5: How can I copy a file?
>>
>> (contributed by brian d foy)
>>
>> Use the File::Copy module. It comes with Perl and can do a true copy
>> across file systems, and it does its magic in a portable fashion.
>>
>> use File::Copy;
>>
>> copy( $original, $new_copy ) or die "Copy failed: $!";
>>
>> If you can't use File::Copy, you'll have to do the work yourself: open
>> the original file, open the destination file, then print to the
>> destination file as you read the original.
>
> What is the advantage of using this over using system("cp $original
> $new_copy"); (or system("copy $original $new_copy"); on windows)?
I think you just answered your question: The advantage is that you can
just write
copy( $original, $new_copy )
instead of
if (os_is_some_kind_of_unix()) {
system("cp", $original, $new_copy);
} elsif (os_is_windows()) {
system("copy", $original, $new_copy);
} else {
...
}
and wonder how you can write sub os_is_some_kind_of_unix.
(and you won't make stupid mistakes like system("cp $original
$new_copy"). which won't work if either $original or $new_copy contains
any of a large number of "dangerous" characters)
OTOH, when you use a system-specific tool like "cp", you can do
system-specific things, like preserve permissions or timestamps.
> Is it faster
It is probably faster for small files. It also is more robust (even if
the system has a "cp" command, it may not be in your path).
> or is it just "perlish"?
That, too.
hp
------------------------------
Date: Sun, 08 Jun 2008 16:55:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to change the date format of all my htmls?
Message-Id: <6b2a3eF34j5saU1@mid.individual.net>
robertchen117@gmail.com wrote:
> I have many html files in my directory, I want to change all date with
> dd/mm/yy format to /mm/dd/yyyy in the files.
Wouldn't it be better to change them to the non-ambiguous international
standard format yyyy-mm-dd
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 8 Jun 2008 09:21:17 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: how to change the date format of all my htmls?
Message-Id: <slrng4nqmt.vaa.tadmc@tadmc30.sbcglobal.net>
robertchen117@gmail.com <robertchen117@gmail.com> wrote:
> I have many html files in my directory, I want to change all date with
> dd/mm/yy format to /mm/dd/yyyy in the files.
Should 01/01/01 result in 01/01/1801 or 01/01/1901 or 01/01/2001 or ...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 8 Jun 2008 12:11:32 -0700
From: "Yuri Shtil" <shtil@comcast.net>
Subject: How to find memory leak in perl server
Message-Id: <DqSdnVNY4KVws9HVnZ2dnUVZ_jadnZ2d@comcast.com>
Hi All,
I have written an event driven network server in perl. However, when running
tests I see that the server process increases in memory and slows down.
How would you recommend to approach the problem? What to look for in order
to identify the cause of the memory leaks?
--
Y
------------------------------
Date: Sun, 8 Jun 2008 21:22:50 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: Order of operations
Message-Id: <g2hija$iq4$1@reader2.panix.com>
In article <E56Zj.174357$yE1.60@attbi_s21>,
Michael Carman <mjcarman@mchsi.com> wrote:
>Ben Morrow wrote:
>> Quoth "John W. Krahn" <krahnj@telus.net>:
>>> I've had this discussion on c.l.p.misc before and it has been (rightly)
>>> pointed out to me that precedence does not determine order of evaluation.
>>
>> Can you give me an example? I can't really see how the yacc parser can
>> produce anything else...
>
>Roughly speaking: Precedence defines the order in which operations are
>performed. Order of evaluation defines the order in which the operands
>are evaluated. Even if the parser always returns a particular order an
>optimizing stage could decide to reorder things.
>
>So in "f() + g() * h()" precedence says that the multiplication happens
>before the addition but it does not dictate which order the functions
>are called in. That's determined by the order of evaluation. If the
>three functions are independent it doesn't matter, but if they have side
>effects (like modifying shared global data) it could.
>
>-mjc
So that means that you have to REMEMBER which funcs have (unexpected or unobvious)
side-effects. Meaning you gotta have a func-name-suffix "SE" or the like
to remind you.
Well, there is someone else who knows, or could easily know, who has
side effects, and can propogate that knowledge (well, infection) to
calling funcs, and warn us of such potentially dangerous (and *horribly*
difficult to track-down) uses within expressions.
Who might that be? THE COMPILER, OF COURSE!
(maybe including the runtime-loader of other modules?)
Wouldn't it be reasonable to have the compiler (-w) warn of this
stuff?
(Presumably, it already does!)
David
PS: even in cases where you can prove that there's no problem,
due to some if-sequence guaranteeing that certain problems
cannot occur -- eliminating such uses wouild be a huge help
to those who follow and have to *maintain* such code!
Just think to that date-2k problem, with the discovery of all
those 30-year-old COBOL still very much in critical use!
David
------------------------------
Date: Sun, 8 Jun 2008 15:21:05 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Performance on Windows: Cygwin is much faster. Why?
Message-Id: <slrng4nn61.9ut.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-07 23:04, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> 5.10 seems to be a bit slower, but not much:
>>
>> 5.8.8 as included in Debian Etch:
>> Found X=133481 in 325 seconds, Y=447352 in 573 seconds.
>>
>> 5.10.0 (compiled from source with default options):
>> Found X=133481 in 343 seconds, Y=447352 in 597 seconds.
>
> Both of these were built with 32bit IVs
Yes.
>(why on earth do Debian do that? The stock FreeBSD perl is built with
>64bit IVs, even on a 32bit system...)
Presumably because its the default and the Debian maintainer didn't see
a strong reason to change it. (I didn't, either - the 5.10.0 I compiled
myself also uses 32 bit IVs)
>> (both run on the same system:
>> Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz)
>>
><snip>
>> Found X=133481 in 139 seconds, Y=447352 in 245 seconds.
>>
>> (Intel(R) Xeon(R) CPU X5355 @ 2.66GHz)
>
> This perl was presumably built with 64bit IVs...
Yes. It's on a 64bit system.
>> So 64 bit at 43% higher clock rate seems to be 134% faster than 32 bit -
>> quite impressive (but it's a different CPU, too - so that might be
>> deceptive)
>
> ...so, again, you're comparing FP to integer arithmetic.
Yes. I still think it's impressive. I would have expected the difference
between FP and integer arithmetic to be dwarfed by the interpreter
overhead.
hp
------------------------------
Date: Sun, 08 Jun 2008 17:21:18 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Perl grep and Perl 4
Message-Id: <86ej77ei7l.fsf@mithril.chromatico.net>
>>>>> "szr" == szr <szrRE@szromanMO.comVE> writes:
szr> That's assuming that he wasn't stuck with a server that had
szr> only Perl 4 on it (and insufficient privileges to install a
szr> newer one.)
>> Right, which is a bizarre choice, verging on a pathology, on the
>> part of the host.
>> Perl 4 was superseded by Perl 5 a decade and a half ago.
szr> True. My point is not everyone is has quite grasped the concept
szr> of being up to date.
But there's a difference between not being up to date and taking active
steps to remain out of date, and using Perl 4 in 2008 counts as the
latter.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Sun, 8 Jun 2008 14:58:30 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: Tk with Thread
Message-Id: <b08776ae-b226-49d4-836e-1fe9f7582162@e39g2000hsf.googlegroups.com>
I try to use Excel OLE but it crashes when I click exit.
Is there a way to work around?
use strict;
use warnings;
#use Win32::OLE;
#use Win32::OLE::Const 'Microsoft Excel';
use Tk;
use Tk::Balloon;
use threads;
use threads::shared;
my $run:shared = 0;
my $exit:shared = 0;
my $count:shared = 0;
my $thr = threads->new(\&new_thread);
my $mainWindow = MainWindow->new;
my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7,
-scrollbars=>"ose", -wrap=>"word")->grid();
$mainWindow->Button(-foreground=>"blue", -text=>"Click",
-command=>\&excecute)->grid();
my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Stop",
-command=>sub{ $run=0; })->grid();
$mainWindow->Button(-foreground=>"black", -text=>"exit",
-command=>sub{ $exit=1;
$thr->join;
exit;
})->grid();
my $repeater = $mainWindow->repeat(1000,sub{
if($run){
$textBox->insert('end', "$count\n");
$textBox->see('end');
$textBox->update;
$stopBut->configure(-state=> "disabled");
}
});
MainLoop;
sub new_thread{
while(1)
{
if($exit){ return; } #thread can only be joined after it
returns
if($run)
{
if($exit){return;}
&test;
}
else
{
## Sleep for 1 miliseconds
select(undef,undef,undef,.1);
}
}
}
sub test{
$count++;
}
sub excecute { $run = 1 }
------------------------------
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 V11 Issue 1621
***************************************