[30374] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1617 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 6 18:09:40 2008

Date: Fri, 6 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           Fri, 6 Jun 2008     Volume: 11 Number: 1617

Today's topics:
    Re: $# array creation and data rotation sln@netherlands.co
    Re: <<EndOfMessage <smallpond@juno.com>
        hollywood and bollywood <priyasexy737@gmail.com>
    Re: OT: SI units <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: OT: SI units <joost@zeekat.nl>
    Re: OT: SI units <willem@stack.nl>
        Perl CGI Issue <venner@gmail.com>
    Re: Perl CGI Issue <1usa@llenroc.ude.invalid>
    Re: Perl CGI Issue <1usa@llenroc.ude.invalid>
    Re: Perl CGI Issue <danrumney@warpmail.net>
    Re: Perl CGI Issue <venner@gmail.com>
    Re: Perl CGI Issue <danrumney@warpmail.new>
    Re: Questions about "perldoc perlembed" <jl_post@hotmail.com>
    Re: regex back matching <tzz@lifelogs.com>
    Re: regex back matching <szrRE@szromanMO.comVE>
    Re: Stopping a File::Find on first find (Darren Dunham)
    Re: TCP apllications (Jens Thoms Toerring)
    Re: TCP apllications <zentara@highstream.net>
    Re: TCP apllications <tzz@lifelogs.com>
    Re: Tk with Thread <slick.users@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 06 Jun 2008 10:17:06 -0700
From: sln@netherlands.co
Subject: Re: $# array creation and data rotation
Message-Id: <7rri44hkj1ufdcc6pcmj3ejg9igfqpi1rc@4ax.com>

On Sun, 01 Jun 2008 13:28:09 -0800, Hobart Duncan <hobart@doitsweb.net> wrote:

>This newbie need some technical information:
>
>....after the creation of an array of (just for grins..) 10 integers read in
>from (more grins....) the serial port, what is the proper way to maintain the
>array to ONLY 10 values?
>
>I want to first create an array: .... $#Test = sprintf (%d, 100/10)
>
>now, as data comes in via the serial port (I keeping everything in decimal) I
>first want to "shift" the data: shift (@Test)
>
>and then push the new data: push (@Test, newdata).
>
>After the new data is inserted, I perform calculations (averages, etc) and then
>move on..... until the next loop when the shift and push are executed again.
>
>Because I am not using the shifted data, does the shift statement just pull the
>data and throw it away? .... and is this a safe way to rotate the data within
>the array?
>
>Tnx, in advance....
>Hobart

You could do a little more fancy ring buffer:
====================

use strict;
use warnings;

my $head = 0;
my $tail = 0;
my $bufsize = 10;
my @ringbuffer = ();


my ($i, $val);
for ($i = 0; $i < 26; $i++)
{
	if (!AddHead ( $i )) {
		print "Buffer will overflow, take some off first\n";
		while (RemoveTail( \$val )) {
			print "val= $val\n";
		}
		$i--;
	}
}
print "Cleaning out buffer\n";
while (RemoveTail( \$val )) {
	print "val= $val\n";
}


sub AddHead
{
	my $tmp = $head+1;
	$tmp = 0 if ($tmp > $bufsize);
	return 0 if ($tmp == $tail);
	$head = $tmp;
	$ringbuffer[$head] = shift;
	return 1;
}
sub RemoveTail
{
	my $refval = shift;
	die "RemoveTail(): Parameter required.\n" if(!defined($refval));
	return 0 if ($head == $tail);
	$tail++;
	$tail = 0 if ($tail > $bufsize);
	$$refval = $ringbuffer[$tail];
	return 1;
}

===========
sln




------------------------------

Date: Fri, 06 Jun 2008 09:46:17 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: <<EndOfMessage
Message-Id: <6d646$48493fb1$8514@news.teranews.com>

April wrote:
> Need help on the following piece ...
> 
> $MTo = 'someone@someplace.com';
> $MSubject = 'Something';
> open(DOMAIL, "| mail -s $Msubject $MTo");
> print DOMAIL <<"EndOfMessage";
> First half mail body,
> Second half mail body.
> EndOfMessage
> 
> Does this mean the mail body before EndOfMessage will be sent to
> filehandle DOMAIL, which inturn will be piped to mail for sending out?
> 
> What does << in the print statement mean?  Have seen < read, > write,
> and >> append, but couldn't find <<.

Note that if you have spaces in your subject, this will not work.
You should add escaped quotes around $Msubject to your mail command.
-S
** Posted from http://www.teranews.com **


------------------------------

Date: Fri, 6 Jun 2008 08:06:54 -0700 (PDT)
From: 12 <priyasexy737@gmail.com>
Subject: hollywood and bollywood
Message-Id: <709c4bfa-8a92-4253-be51-297b6190ff97@q24g2000prf.googlegroups.com>

hollywood and bollywood
hindi movies
downloads etc
------------------------
http://bibasabasu.blogspot.com
-------------------------------


------------------------------

Date: Fri, 06 Jun 2008 18:32:18 +0000
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: OT: SI units
Message-Id: <484982b2$0$892$ba4acef3@news.orange.fr>

A. Sinan Unur wrote:
> To meter is to measure. I am finding it increasingly obnoxious (as my 
> years in the U.S. add up) that the French decided to impose on the rest 
> of the world the one true system of measurement and co-op a generic term 
> meaning to measure/measurement for that purpose.
The French spell it "mètre", and the British "metre" (I don't know how 
it's spelt in other forms of English). Spelt those ways it doesn't seem 
all that obnoxious at all :)


------------------------------

Date: Fri, 06 Jun 2008 21:05:58 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: OT: SI units
Message-Id: <87abhy9yeh.fsf@zeekat.nl>

Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr> writes:

> A. Sinan Unur wrote:
>> To meter is to measure. I am finding it increasingly obnoxious (as
>> my years in the U.S. add up) that the French decided to impose on
>> the rest of the world the one true system of measurement and co-op a
>> generic term meaning to measure/measurement for that purpose.
> The French spell it "mètre", and the British "metre" (I don't know how
> it's spelt in other forms of English). Spelt those ways it doesn't
> seem all that obnoxious at all :)

Just as an additional data point; in Dutch the unit/noun is "meter",
while the translations of the *verb* "measuring" / "measure" and the
noun "measurement" in Dutch are "meten" / "meet" / "meting"
respectively. Definitely related but also not that easily confused.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


------------------------------

Date: Fri, 6 Jun 2008 19:44:06 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: OT: SI units
Message-Id: <slrng4j4s6.5uj.willem@snail.stack.nl>

Joost wrote:
) Just as an additional data point; in Dutch the unit/noun is "meter",
) while the translations of the *verb* "measuring" / "measure" and the
) noun "measurement" in Dutch are "meten" / "meet" / "meting"
) respectively. Definitely related but also not that easily confused.

And what do you call someone (or something) who measures ? :-)


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Fri, 6 Jun 2008 12:53:44 -0700 (PDT)
From: Eric <venner@gmail.com>
Subject: Perl CGI Issue
Message-Id: <ec87562b-c320-46a8-9ac9-4c2218e19599@k37g2000hsf.googlegroups.com>

Hello,

I'm having an issue with a perl CGI script.  The code looks like this:

#!/usr/bin/perl
use CGI;
use IO::Handle;

$|=1;

[... snip ...]

# Redirect the user to the appropriate output page.
$io = new IO::Handle;
if ($io->fdopen(fileno(STDOUT),"w")) {
    $io->print("Output:output.php?load=$sum/$pdbid.html\n");
    $io->flush() || die $!;
}

system("cmd & perl backend.pl $pdbid $sum");    # takes about 4
minutes to run

My web page makes an AJAX post to this cgi script to start the
"backend" process.  Since that process takes a few minutes, I would
like the user to be taken to a waiting page.  However, I need to pass
that $sum variable back to the page.

In my head, this code should print the output message to stdout, start
the backend.pl script in the background, exit and then send the
contents of stdout down to the web page.

In actuality what happens is there is a delay of several minutes
before the output message is sent to the page.  However, it is not the
full amount of time required to run backend.pl.  It seems to be pretty
consistently about half of the required time.  The page then gets the
output message, and redirects to the waiting page and works fine from
thereon out.

Does anyone know how I can get that output message to my webpage
immediately?  As you can see I've tried flushing stdout several
different ways with no luck.

Also, if there is a better group for me to post to, that would be
appreciated too.

Thanks,
Eric


------------------------------

Date: Fri, 06 Jun 2008 20:05:29 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl CGI Issue
Message-Id: <Xns9AB5A3AF2371Fasu1cornelledu@127.0.0.1>

Eric <venner@gmail.com> wrote in news:ec87562b-c320-46a8-9ac9-4c2218e19599
@k37g2000hsf.googlegroups.com:

> if ($io->fdopen(fileno(STDOUT),"w")) {
>     $io->print("Output:output.php?load=$sum/$pdbid.html\n");
>     $io->flush() || die $!;
> }

 ...

> Also, if there is a better group for me to post to, that would be
> appreciated too.

I will recommend the main page at http://thedailywtf.com/

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Fri, 06 Jun 2008 20:23:34 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl CGI Issue
Message-Id: <Xns9AB5A6C07FD5Easu1cornelledu@127.0.0.1>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns9AB5A3AF2371Fasu1cornelledu@127.0.0.1: 

> Eric <venner@gmail.com> wrote in
> news:ec87562b-c320-46a8-9ac9-4c2218e19599 
> @k37g2000hsf.googlegroups.com: 
> 
>> if ($io->fdopen(fileno(STDOUT),"w")) {
>>     $io->print("Output:output.php?load=$sum/$pdbid.html\n");
>>     $io->flush() || die $!;
>> }
> 
> ...
> 
>> Also, if there is a better group for me to post to, that would be
>> appreciated too.
> 
> I will recommend the main page at http://thedailywtf.com/

I am afraid everyone is going to get on my case for being rude again, so 
let me ask you to please kindly explain what you are doing.

In general, the way to print to STDOUT in Perl is to

print "Output:output.php?load=$sum/$pdbid.html\n";

Sometimes you might have to explicitly specify the filehandle:

print STDOUT "Output:output.php?load=$sum/$pdbid.html\n";

The Perl only code you present in your post (well, OK, there is call to 
system) is what I have quoted above. I am baffled as to what you think 
this does and why you think you need it.

On the other hand, my powers of mental-telemetapathy tell me that you 
might be interested in 

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

On the other hand, that may not be as webtwomoey and ajaxamahahey for 
you.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Fri, 06 Jun 2008 16:32:03 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: Re: Perl CGI Issue
Message-Id: <48499eb0$0$31751$4c368faf@roadrunner.com>

A. Sinan Unur wrote:
> Eric <venner@gmail.com> wrote in news:ec87562b-c320-46a8-9ac9-4c2218e19599
> @k37g2000hsf.googlegroups.com:
> 
>> if ($io->fdopen(fileno(STDOUT),"w")) {
>>     $io->print("Output:output.php?load=$sum/$pdbid.html\n");
>>     $io->flush() || die $!;
>> }
> 
> ...
> 
>> Also, if there is a better group for me to post to, that would be
>> appreciated too.
> 
> I will recommend the main page at http://thedailywtf.com/

I believe this is a rather unhelpful way of indicating that that's some 
very convoluted code to write to STDOUT.

use IO::Handle;
STDOUT->autoflush(1);
print "Output:output.php?load=$sum/$pdbid.html\n";

would suffice

Or maybe the confusion is about your use of "Output:"
That's not an HTTP header that I'm aware of. If you're trying to 
redirect a User Agent, "Location:" would be the appropriate header


------------------------------

Date: Fri, 6 Jun 2008 13:46:28 -0700 (PDT)
From: Eric <venner@gmail.com>
Subject: Re: Perl CGI Issue
Message-Id: <871a5202-3e59-4d45-a907-33ef9883124a@x41g2000hsb.googlegroups.com>

On Jun 6, 3:23 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote innews:Xns9AB5A3AF2371Fasu1cornelledu@127.0.0.1:
>
> > Eric <ven...@gmail.com> wrote in
> > news:ec87562b-c320-46a8-9ac9-4c2218e19599
> > @k37g2000hsf.googlegroups.com:
>
> >> if ($io->fdopen(fileno(STDOUT),"w")) {
> >>     $io->print("Output:output.php?load=$sum/$pdbid.html\n");
> >>     $io->flush() || die $!;
> >> }
>
> > ...
>
> >> Also, if there is a better group for me to post to, that would be
> >> appreciated too.
>
> > I will recommend the main page athttp://thedailywtf.com/
>
> I am afraid everyone is going to get on my case for being rude again, so
> let me ask you to please kindly explain what you are doing.
>
> In general, the way to print to STDOUT in Perl is to
>
> print "Output:output.php?load=$sum/$pdbid.html\n";
>
> Sometimes you might have to explicitly specify the filehandle:
>
> print STDOUT "Output:output.php?load=$sum/$pdbid.html\n";
>
> The Perl only code you present in your post (well, OK, there is call to
> system) is what I have quoted above. I am baffled as to what you think
> this does and why you think you need it.
>
> On the other hand, my powers of mental-telemetapathy tell me that you
> might be interested in
>
> http://www.stonehenge.com/merlyn/LinuxMag/col39.html
>
> On the other hand, that may not be as webtwomoey and ajaxamahahey for
> you.
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/

Thanks for responding.  I'm actually very new to both perl and cgi
scripting, so I really appreciate your kind and professional attidute.

Initially that line looked like this:
print "Output:output.php?load=$sum/$pdbid.html\n"

However, that message was not sent to the page in as timely a fashion
as I would like, so I tried setting autoflush.  Still no go, so I
found that you can manually flush a buffer if you use that module.  I
left it in both that line and the autoflush above it the hopes that it
would give you some idea of what I've already tried.

The "Output:" is simply a keyword that the page looks for when
deciding what to do with a message from the message from the cgi page.

Thanks,
Eric


------------------------------

Date: Fri, 06 Jun 2008 17:21:46 -0400
From: Dan Rumney <danrumney@warpmail.new>
Subject: Re: Perl CGI Issue
Message-Id: <4849aa62$0$31756$4c368faf@roadrunner.com>

Eric wrote:
  [snip]

> # Redirect the user to the appropriate output page.
> $io = new IO::Handle;
> if ($io->fdopen(fileno(STDOUT),"w")) {
>     $io->print("Output:output.php?load=$sum/$pdbid.html\n");
>     $io->flush() || die $!;
> }
> 
> system("cmd & perl backend.pl $pdbid $sum");    # takes about 4
> minutes to run
> 
> My web page makes an AJAX post to this cgi script to start the
> "backend" process.  Since that process takes a few minutes, I would
> like the user to be taken to a waiting page.  However, I need to pass
> that $sum variable back to the page.

[snip]

> In actuality what happens is there is a delay of several minutes
> before the output message is sent to the page.  However, it is not the
> full amount of time required to run backend.pl.  It seems to be pretty
> consistently about half of the required time.  The page then gets the
> output message, and redirects to the waiting page and works fine from
> thereon out.

[snip]

Having thought about this further, I think your problem may have more to 
do with how web servers serve pages and how clients handle webserver 
responses.

IIRC, the default timeout for a webserver is something in the region of 
2 minutes. If a request for a resource (in this case, your dynamic page) 
is not completed before the timeout is up, then the server will close 
the output stream.

On the client-side, your AJAX request will sit there, waiting for the 
request to complete before it changes to readyState=4 (loaded) and I 
would bet you a shekel that your code waits until readyState=4 before it 
does anything with it.

If the above is true then that would probably explain why the client 
waits half the backend run time (i.e. 2 minutes) before doing anything.

You can confirm the behaviour of your script by actually running it from 
the command line. That will show you once and for all the point at which 
the "Output:" string is being printed




------------------------------

Date: Fri, 6 Jun 2008 14:17:13 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Questions about "perldoc perlembed"
Message-Id: <93b86eca-d634-43bd-96ac-286a66c3cf4c@r66g2000hsg.googlegroups.com>

I previously wrote:
>
>   Ultimately I am trying to embed the ability to
> run Perl scripts on a C++ program written in
> Visual Studio 2005 (on a Windows XP machine).

   Wow... thanks for the quick responses, Ben and Rob.  I appreciate
them.

   Thanks to your help, I was able to make some progress, although I'm
still having a few problems here and there.  I'm going to try to work
them out on my own for now.

   Again, thank you both very much.

   -- Jean-Luc


------------------------------

Date: Fri, 06 Jun 2008 09:33:55 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: regex back matching
Message-Id: <86abhyzl7w.fsf@lifelogs.com>

On Thu, 5 Jun 2008 16:55:25 -0700 (PDT) "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com> wrote: 

clpm> Even if they're well commented, regex's can become very obscure if
clpm> they're more than one line :)

Sometimes it's inevitable.  Using comments helps a lot with Perl 5, but
in the end regular expressions are the assembly language of Perl 5: both
its most outstanding and its most baffling (to new users) feature.

Parse::RecDescent and Perl 6 grammars are going in the other direction,
away from complexity and towards extracting patterns and syntax (lexing
and parsing).

Ted


------------------------------

Date: Fri, 6 Jun 2008 10:23:15 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: regex back matching
Message-Id: <g2brq401ish@news4.newsguy.com>

Martijn Lievaart wrote:
> On Thu, 05 Jun 2008 13:19:10 -0700, szr wrote:
>
>> It is a tool (the one on my system is from GNU, v2.5.1), which is
>> used for finding lines in plain text by a given pattern. egrep is
>> basically a shortcut for `grep -e'. One could also use `grep -P` for
>> a Perl style RE.
>
> ITYM `grep -E'.
>
> M4

Fromgrep's --help:

  -E, --extended-regexp     PATTERN is an extended regular expression
  -F, --fixed-strings       PATTERN is a set of newline-separated 
strings
  -G, --basic-regexp        PATTERN is a basic regular expression
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -e, --regexp=PATTERN      use PATTERN as a regular expression

Are you saying -E equates to egrep? I'm starting to think that may be 
the case after reading the above.

-- 
szr 




------------------------------

Date: Fri, 06 Jun 2008 16:44:23 GMT
From: ddunham@taos.com (Darren Dunham)
Subject: Re: Stopping a File::Find on first find
Message-Id: <HPd2k.5050$jI5.3202@flpi148.ffdc.sbc.com>

jl_post@hotmail.com <jl_post@hotmail.com> wrote:

>   First, I created a variable to keep track if I had what I wanted:
> 
>      my $found = 0;  # initialize to false
> 
> Then I put it in the wanted() function (the one that File::Find()
> uses) like this:
> 
>      sub wanted
>      {
>         return  if $found;

Change that to..
          $File::Find::prune = 1 if $found;

>   To stop File::Find() from traversing the directory trees, I made
> use of the "preprocess" option (it's documented in "perldoc
> File::Find").  I just created a function like:

prune would be the standard way to do that.

-- 
Darren


------------------------------

Date: 6 Jun 2008 13:19:00 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: TCP apllications
Message-Id: <6asrq4F37li54U1@mid.uni-berlin.de>

Arun <sajapuram.arun.prakash@gmail.com> wrote:
> This is Arun here, i am new to Perl so i
> was just thinking of programming the TCP apllications or working. So
> how do i do that, just needed guidance from you.

To get "guidance" you have to specify more clearly where you want
to go. What is "the TCP apllications or working"? If you want to
know how to open a socket have a look at the Socket package or,
for an OO approach, IO::Socket::Inet etc. E.g. to run a server,
listening on port 80 (HTTP), allowing up to 10 concurrent con-
nections, all you need is

use warnings;
use strict;
use IO::Socket::INET;

my $server = IO::Socket::INET->new( LocalPort => 80,
                                    Type      => SOCK_STREAM,
                                    Reuse     => 1,
                                    Listen    => 10,
                                    Proto     => 'tcp' );

while ( 1 ) {
    my $client = $server->accept( );
    next unless defined $client;    # accept() failed
    if ( my $pid = fork ) {         # parent on success
        close $client;              # going to wait for the next client
    } else {                        # here comes the child's code
        serve( $client );           # service request from client
        exit 0;                     # just in case serve() didn't do it
    }
}

All left to be done is writting the serve() function that implements
the HTTP protocol (or whatever other protocol you want to use).

                             Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


------------------------------

Date: Fri, 06 Jun 2008 09:36:55 -0400
From: zentara <zentara@highstream.net>
Subject: Re: TCP apllications
Message-Id: <87fi449209p0o7tfu194ablis7uib0optf@4ax.com>

On Fri, 6 Jun 2008 04:28:22 -0700 (PDT), Arun
<sajapuram.arun.prakash@gmail.com> wrote:

>Hi,
>This is Arun here, i am new to Perl so i
>was just thinking of programming the TCP apllications or working. So
>how do i do that, just needed guidance from you.

If you want an easy to use module, that takes care of alot of details,
see Net::EasyTCP

http://search.cpan.org/search?query=Net%3A%3AEasyTCP&mode=all


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html 


------------------------------

Date: Fri, 06 Jun 2008 09:40:41 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: TCP apllications
Message-Id: <8663smzkwm.fsf@lifelogs.com>

On Fri, 6 Jun 2008 04:28:22 -0700 (PDT) Arun <sajapuram.arun.prakash@gmail.com> wrote: 

A> This is Arun here, i am new to Perl so i was just thinking of
A> programming the TCP apllications or working. So how do i do that,
A> just needed guidance from you.

Learn how TCP/IP works, from ARP to the SYN/ACK sequence to session
management.  You don't need to become an expert, just be aware of what
happens on the wire.  Then you'll understand your application much
better and your skills will go beyond "I can open a port and
listen/write to it."  Also, writing the Perl application will be much
easier if you know what's going on underneath and what problems TCP/IP
may cause.

Ted


------------------------------

Date: Fri, 6 Jun 2008 15:03:28 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: Tk with Thread
Message-Id: <60fc5f93-3ee7-4758-ba47-05841e8c96bb@a70g2000hsh.googlegroups.com>

Can you explain this line of the code about the sleep and what is .1
for?

select undef,undef,undef,.1; #sleep awhile

Thx.

On May 20, 5:40 am, zentara <zent...@highstream.net> wrote:
> On Mon, 19 May 2008 17:16:44 -0700 (PDT),Slickuser
>
> <slick.us...@gmail.com> wrote:
> >Here is the update code with the same error.
>
> >I would like to be able to move my Tk window when a button is press.
> >Currently, it's freeze until it's done parsing.
>
> I get all sorts of errors regarding thread corruption, since you
> created your thread after Tk is invoked, and you try to access the
> Tk text widget from the thread. Gtk2 will allow you to do that, but Tk
> won't. Even Gtk2 needs some precautions.
>
> This is a basic Tk thread script, to show you the ropes.
> You can search groups.google.com for "perl Tk threads"
> and find all of the many examples that have been posted previously.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Tk;
> use threads;
> use threads::shared;
>
> my $go:shared = 0;
> my $die:shared = 0;
> my $count:shared = 0;
>
> # make thread before any Tk is called,
> # usually a sleeping thread
> my $thr = threads->new(\&new_thread);
>
> my $mainWindow = MainWindow->new;
> my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7,
>       -scrollbars=>"ose", -wrap=>"word")->pack();
>
> $mainWindow->Button(-foreground=>"blue", -text=>"Click",
>                    -command=>\&excecute)->pack();
>
> $mainWindow->Button(-foreground=>"red", -text=>"Stop",
>                    -command=>sub{ $go=0 })->pack();
>
> $mainWindow->Button(-foreground=>"black", -text=>"exit",
>                    -command=>sub{ $die=1;
>                                   $thr->join;
>                                   exit;
>                                    })->pack();
>
> # you must actively read the shared variables with a timer
> # filehandles can be shared thru the fileno,
> # search groups.google for examples
> my $repeater = $mainWindow->repeat(1000,sub{
>             if($go){
>               $textBox->insert('end', "$count\n");
>               $textBox->see('end');
>               $textBox->update;
>              }
>             });
>
> MainLoop;
>
> sub new_thread{
>
>     while(1){
>        if($die){return}    #thread can only be joined after it returns
>        if( $go == 1){
>            if($die){return}
>
>           $count++;
>
>        }else{ select undef,undef,undef,.1}  #sleep awhile
>     }
>
> }
>
> sub excecute { $go = 1 }
> __END__
>
>  Those are the basics, but search groups.google.com, because
> we have answered these questions many times before, with code examples.
>
> zentara
>
> --
> I'm not really a human, but I play one on earth.http://zentara.net/japh.html



------------------------------

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 1617
***************************************


home help back first fref pref prev next nref lref last post