[29801] in Perl-Users-Digest
Perl-Users Digest, Issue: 1044 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 20 16:09:42 2007
Date: Tue, 20 Nov 2007 13:09:07 -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 Tue, 20 Nov 2007 Volume: 11 Number: 1044
Today's topics:
Re: firefox could open my cgi, IE will be dead, why? <stoupa@practisoft.cz>
Re: firefox could open my cgi, IE will be dead, why? <pgovern@u.washington.edu>
Perl Tk: long running callback loses GUI interactivity <andygough1974@gmail.com>
Re: Perl Tk: long running callback loses GUI interactiv sheinrich@my-deja.com
Re: Perl Tk: long running callback loses GUI interactiv <smallpond@juno.com>
Re: Perl Tk: long running callback loses GUI interactiv <stoupa@practisoft.cz>
Re: Perl Tk: long running callback loses GUI interactiv <smallpond@juno.com>
Re: Print Line number as script runs.. <jl_post@hotmail.com>
Re: Question about XML::Generator <hjp-usenet2@hjp.at>
Re: Regular expression help <tadmc@seesig.invalid>
Re: Regular expression help <mritty@gmail.com>
Re: Regular expression help <jurgenex@hotmail.com>
Re: Regular expression help <5502109103600001@t-online.de>
Re: Regular expression help <cwilbur@chromatico.net>
Re: Script to disconnect Linksys WRT54G wireless router <davewilson69@sbcglobal.net>
Re: Why this file download CGI works with Firefox and f <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Nov 2007 17:39:46 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: firefox could open my cgi, IE will be dead, why?
Message-Id: <fhv30j$dhb$2@ns.felk.cvut.cz>
robertchen117@gmail.com wrote:
> my cgi is very simple, just output the file's content. the file name
> is from another cgi's parameter.
>
> If I use firefox visist the page, no issues at all! Everything looks
> great. But if I use Internet Explorer, the cgi will make IE to die.
> Please help me.
>
> #!/tivoli/vendor/perl/bin/perl
> use CGI;
> #rchen on 4/10
>
> my $cgi = new CGI;
> print $cgi->header(-type=>"text/html", -expires=>'now');
> print $cgi->start_html("Details of the configurations");
>
> my $logfile = $cgi->param('logfile');
> open(DATA, "$logfile")|| die("File is not exist!\n");
>
> @lines = <DATA>;
>
> foreach $line (@lines) {
> print "<PRE>$line <\PRE>";
> }
>
> close(DATA);
> print $cgi->end_html;
I tried to bit improve your script. All changes are closed to #### lines and
original lines are commented by ##.
#!/tivoli/vendor/perl/bin/perl
use CGI;
###############
use strict;
###############
#rchen on 4/10
my $cgi = new CGI;
print $cgi->header(-type=>"text/html", -expires=>'now');
print $cgi->start_html("Details of the configurations");
my $logfile = $cgi->param('logfile');
## open(DATA, "$logfile")|| die("File is not exist!\n");
###############
open(DATA, "$logfile") or die("File not exist or not permission to
read!\n");
###############
## @lines = <DATA>;
## foreach $line (@lines) {
###############
while (my $line = <DATA>) {
###############
print "<PRE>$line <\PRE>";
}
close(DATA);
print $cgi->end_html;
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Tue, 20 Nov 2007 09:34:34 -0800 (PST)
From: patrick <pgovern@u.washington.edu>
Subject: Re: firefox could open my cgi, IE will be dead, why?
Message-Id: <47c8f215-382e-4e3b-bc91-79ccc1a6d86f@s36g2000prg.googlegroups.com>
On Nov 19, 10:31 pm, "robertchen...@gmail.com"
<robertchen...@gmail.com> wrote:
> my cgi is very simple, just output the file's content. the file name
> is from another cgi's parameter.
>
> If I use firefox visist the page, no issues at all! Everything looks
> great. But if I use Internet Explorer, the cgi will make IE to die.
> Please help me.
>
> #!/tivoli/vendor/perl/bin/perl
> use CGI;
> #rchen on 4/10
>
> my $cgi = new CGI;
> print $cgi->header(-type=>"text/html", -expires=>'now');
> print $cgi->start_html("Details of the configurations");
>
> my $logfile = $cgi->param('logfile');
> open(DATA, "$logfile")|| die("File is not exist!\n");
>
> @lines = <DATA>;
>
> foreach $line (@lines) {
> print "<PRE>$line <\PRE>";
>
> }
>
> close(DATA);
> print $cgi->end_html;
You're using <\PRE> when should be </PRE>
Why <PRE> line </PRE> instead of
<PRE> line
line
line
</PRE>?
------------------------------
Date: Tue, 20 Nov 2007 06:42:25 -0800 (PST)
From: andy <andygough1974@gmail.com>
Subject: Perl Tk: long running callback loses GUI interactivity
Message-Id: <27fce768-3cdf-40bb-8b9b-49e51b4562dc@e1g2000hsh.googlegroups.com>
Hi,
I wonder if anyone can help me with a small perl Tk problem I have. I
am writing an automated test script for a digital radio system, when
the user has selected all the options for the test and hits GO in the
GUI the callback executes a long running script, when this happens the
Tk GUI is completley inactive until the call back is finished (which
can take hours). Ideally i'd still like the GUI to have some
interactivity, suck as a CANCEL button to stop the tests (currently I
have to do a Ctrl-C in the dos window to stop the test). Is there a
way to do this? I wasnt sure what search terms to look for when
investigating a solution.
Many thanks in advance,
Andy
------------------------------
Date: Tue, 20 Nov 2007 07:27:57 -0800 (PST)
From: sheinrich@my-deja.com
Subject: Re: Perl Tk: long running callback loses GUI interactivity
Message-Id: <b086b1f3-65c3-429d-9544-0a701a638294@o6g2000hsd.googlegroups.com>
On Nov 20, 3:42 pm, andy <andygough1...@gmail.com> wrote:
> GUI the callback executes a long running script, when this happens the
> Tk GUI is completley inactive until the call back is finished (which
> can take hours). Ideally i'd still like the GUI to have some
This is no issue with perl or tk. The implications are very much the
same with any language across all OSes.
You are apparently running a single process.
I don't know, but tk might have its build-in solutions for a rather
central point in gui functionality.
Else look up "IPC", "parallel" and "fork" in your favourite perl docs
and on CPAN.
You have multiple options to deal with user interaction.
- Your long lasting program might occasionally check for user input to
process.
- You can start an own process with fork() for the long routine and
can steer the child process by means of IPC (inter process
communication). Usually pipes or signals.
fork() is basically easy to use, if your system is supporting it. Try
one of the many examples and find out.
steffen
------------------------------
Date: Tue, 20 Nov 2007 07:46:02 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Perl Tk: long running callback loses GUI interactivity
Message-Id: <d055e3df-9d3a-49ac-b1d8-bed35a1a47e2@d50g2000hsf.googlegroups.com>
On Nov 20, 10:27 am, sheinr...@my-deja.com wrote:
> On Nov 20, 3:42 pm, andy <andygough1...@gmail.com> wrote:
>
> > GUI the callback executes a long running script, when this happens the
> > Tk GUI is completley inactive until the call back is finished (which
> > can take hours). Ideally i'd still like the GUI to have some
>
> This is no issue with perl or tk. The implications are very much the
> same with any language across all OSes.
> You are apparently running a single process.
>
> I don't know, but tk might have its build-in solutions for a rather
> central point in gui functionality.
> Else look up "IPC", "parallel" and "fork" in your favourite perl docs
> and on CPAN.
>
> You have multiple options to deal with user interaction.
> - Your long lasting program might occasionally check for user input to
> process.
> - You can start an own process with fork() for the long routine and
> can steer the child process by means of IPC (inter process
> communication). Usually pipes or signals.
>
> fork() is basically easy to use, if your system is supporting it. Try
> one of the many examples and find out.
>
> steffen
fork() is a good solution. Have the parent return to MainLoop (which
is
what needs to be running for the GUI activity) while the child
executes
your long-running process. system() can be used to start a separate
process that will not interfere with MainLoop. Just be sure to call
it
with 'myprocess &' so it doesn't wait for completion.
--S
------------------------------
Date: Tue, 20 Nov 2007 17:26:19 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Perl Tk: long running callback loses GUI interactivity
Message-Id: <fhv30j$dhb$1@ns.felk.cvut.cz>
andy wrote:
> Hi,
>
> I wonder if anyone can help me with a small perl Tk problem I have. I
> am writing an automated test script for a digital radio system, when
> the user has selected all the options for the test and hits GO in the
> GUI the callback executes a long running script, when this happens the
> Tk GUI is completley inactive until the call back is finished (which
> can take hours). Ideally i'd still like the GUI to have some
> interactivity, suck as a CANCEL button to stop the tests (currently I
> have to do a Ctrl-C in the dos window to stop the test). Is there a
> way to do this? I wasnt sure what search terms to look for when
> investigating a solution.
>
I see you are talking about DOS window ;-) In this case go to CPAN and
search for module ProcFarm. This is something similar to unix fork() but
work very good on Win platform.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Tue, 20 Nov 2007 11:12:20 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Perl Tk: long running callback loses GUI interactivity
Message-Id: <d7fcd640-4458-4cd4-b0c5-03d13c135a5f@c30g2000hsa.googlegroups.com>
On Nov 20, 10:46 am, smallpond <smallp...@juno.com> wrote:
> On Nov 20, 10:27 am, sheinr...@my-deja.com wrote:
>
>
>
> > On Nov 20, 3:42 pm, andy <andygough1...@gmail.com> wrote:
>
> > > GUI the callback executes a long running script, when this happens the
> > > Tk GUI is completley inactive until the call back is finished (which
> > > can take hours). Ideally i'd still like the GUI to have some
>
> > This is no issue with perl or tk. The implications are very much the
> > same with any language across all OSes.
> > You are apparently running a single process.
>
> > I don't know, but tk might have its build-in solutions for a rather
> > central point in gui functionality.
> > Else look up "IPC", "parallel" and "fork" in your favourite perl docs
> > and on CPAN.
>
> > You have multiple options to deal with user interaction.
> > - Your long lasting program might occasionally check for user input to
> > process.
> > - You can start an own process with fork() for the long routine and
> > can steer the child process by means of IPC (inter process
> > communication). Usually pipes or signals.
>
> > fork() is basically easy to use, if your system is supporting it. Try
> > one of the many examples and find out.
>
> > steffen
>
> fork() is a good solution. Have the parent return to MainLoop (which
> is
> what needs to be running for the GUI activity) while the child
> executes
> your long-running process. system() can be used to start a separate
> process that will not interfere with MainLoop. Just be sure to call
> it
> with 'myprocess &' so it doesn't wait for completion.
> --S
My mistake. Tk cannot call fork in a callback. If using fork
in a Tk program, call it before calling MainLoop.
system is OK, tho.
--S
------------------------------
Date: Tue, 20 Nov 2007 11:26:21 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Print Line number as script runs..
Message-Id: <66366e00-e73b-48d6-bbd1-4d99818be639@f13g2000hsa.googlegroups.com>
On Nov 19, 7:16 pm, brian d foy <brian.d....@gmail.com> wrote:
>
> See my article on creating Perl debuggers:
>
> http://www.ddj.com/184404522
Thank-you for sharing that. I found it really useful.
I never knew about "ptkdb" before now. Now I can debug my programs
graphically with "perl -d:ptkdb script.pl" on my ActiveState Perl
distribution (provided I first install ptkdb with "ppm install Devel-
ptkdb").
Thanks again, brian.
-- Jean-Luc Romano
------------------------------
Date: Tue, 20 Nov 2007 21:16:29 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Question about XML::Generator
Message-Id: <slrnfk6g4t.o2r.hjp-usenet2@zeno.hjp.at>
On 2007-11-20 02:48, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth nospam <no@spam.com>:
>> In the perl script below, the $xml is printed just fine. What I need to
>> do is conditionally print some of the xml tags. Something like this:
>>
>> if ($x = $y) {
>> $xml->TAG2A("CCC"),
>> }
>>
>> Of course, you can't place an if statement within the print $xml block.
>> How can I conditionally print one or more of the tags below?
>
> Several ways:
[...]
>> print $xml->TAG1(
>> $xml->TAG1A("AAA"),
>> $xml->TAG1B("BBB"),
>
> do {
> if ($x == $y) {
> $xml->TAG2(...);
> }
> ();
> },
[other ways to do it inside an expression snipped]
Alternatively, you can store the tags you want to use in an array, like
this:
#!/usr/bin/perl
use strict;
use warnings;
use XML::Generator;
my $x = 0;
my $y = 1;
my $xml = XML::Generator->new(pretty => 2, empty => 'compact');
my @tag2 = ();
if ($x == $y) {
push @tag2, $xml->TAG2A("CCC");
}
push @tag2, $xml->TAG2B("DDD");
print $xml->TAG1(
$xml->TAG1A("AAA"),
$xml->TAG1B("BBB"),
$xml->TAG2(
@tag2
),
$xml->TAG3(
$xml->TAG3A("EEE"),
$xml->TAG3B("FFF"),
));
__END__
In this simple example doing it inline is arguably more elegant. In more
complicated cases using variables may be more readable, especially if
they have more descriptive names than "@tag2".
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Mon, 19 Nov 2007 20:38:42 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Regular expression help
Message-Id: <slrnfk4i5i.hho.tadmc@tadmc30.sbcglobal.net>
Benedict White <benedictmpwhite@gmail.com> wrote:
> Many thanks.
To who?
For what?
Please quote some context in followups.
> Is there no simple regex for saying that a part of the text (the bit
> before the @ in this case) can contain anything you like, as long as
> it contains say the number 2?
print "matched\n" if $text =~ /.*2.*\@/s;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Nov 2007 04:44:39 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Regular expression help
Message-Id: <052064cb-a42b-45ca-982b-a5e7757323d9@e4g2000hsg.googlegroups.com>
On Nov 20, 12:46 am, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> Benedict White wrote:
> > Is there no simple regex for saying that a part of the text (the bit
> > before the @ in this case) can contain anything you like, as long as
> > it contains say the number 2?
>
> /.*2.*\@/
>
> will do that.
Interesting that both you and Tad put the useless starting .* in your
regexp. It makes me wonder if it's not as useless as I think it is.
Is there any difference between that and
/2.*\@/
?
Paul Lalli
------------------------------
Date: Tue, 20 Nov 2007 15:58:21 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regular expression help
Message-Id: <xuD0j.9517$Mg1.5772@trndny03>
Paul Lalli wrote:
> On Nov 20, 12:46 am, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>> Benedict White wrote:
>>> Is there no simple regex for saying that a part of the text (the bit
>>> before the @ in this case) can contain anything you like, as long as
>>> it contains say the number 2?
>>
>> /.*2.*\@/
>>
>> will do that.
>
> Interesting that both you and Tad put the useless starting .* in your
> regexp. It makes me wonder if it's not as useless as I think it is.
> Is there any difference between that and
> /2.*\@/
Well, you are right. I can't see any reason to put it there, either.
jue
------------------------------
Date: Tue, 20 Nov 2007 17:20:01 +0100
From: Josef Moellers <5502109103600001@t-online.de>
Subject: Re: Regular expression help
Message-Id: <fhv1gf$65p$03$1@news.t-online.com>
Jürgen Exner wrote:
> Paul Lalli wrote:
>> On Nov 20, 12:46 am, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>>> Benedict White wrote:
>>>> Is there no simple regex for saying that a part of the text (the bit
>>>> before the @ in this case) can contain anything you like, as long as
>>>> it contains say the number 2?
>>> /.*2.*\@/
>>>
>>> will do that.
>> Interesting that both you and Tad put the useless starting .* in your
>> regexp. It makes me wonder if it's not as useless as I think it is.
>> Is there any difference between that and
>> /2.*\@/
>
> Well, you are right. I can't see any reason to put it there, either.
I feel like carrying owls to Athens, but in principle there is a
difference between the two: In the former case (/.*2.*\@/), $PREMATCH
will be empty, in the latter case, (/2.*\@/) it won't.
--
Mails please to josef dot moellers
and I'm on gmx dot de.
------------------------------
Date: 20 Nov 2007 12:10:18 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Regular expression help
Message-Id: <87r6ikderp.fsf@mithril.chromatico.net>
>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
PL> Interesting that both you and Tad put the useless starting .*
PL> in your regexp. It makes me wonder if it's not as useless as
PL> I think it is. Is there any difference between [ /.*2.*\@/ ]
PL> and /2.*\@/ ?
To me, it indicates that the author of the regular expression is
thinking of the 2 as happening somewhere to the left of the @ sign in
the part of the string he cares about, as opposed to the 2 being at
the beginning of the part of the string he cares about.
Starting with the 2 is technically correct, and is only going to make
a difference if $& and company are involved somewhere.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 20 Nov 2007 11:01:29 -0800
From: Wilson <davewilson69@sbcglobal.net>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <hcG0j.21470$Pv2.7332@newssvr23.news.prodigy.net>
Bearing in mind I don't know perl, in the previous perl script to press the
disconnect button on the Linksys WRT54G router ... do these changes seem
correct to you perl programmers?
-----
1. Log in from Windows to the Linksys WRT54G router with a blank username
and a password of "letmein".
INSTEAD OF:
> my $user='root';
> my $pass='letmein';
I WOULD USE:
my $user='';
$pass='letmein';
-----
2. Navigate to the Linksys WRT54G "Status -> Router" web page.
INSTEAD OF:
> my $adr='https://192.168.0.1/Services.asp'; # talk to this
I WOULD USE:
my $adr='https://192.168.0.1/StaRouter.htm'; # talk to this
-----
3. Press the disconnect button on that Status->Router web page.
INSTEAD OF:
> my $req = HTTP::Request->new(POST => $adr,
> ['action','reboot']);
I WOULD USE:
my $req = HTTP::Request->new(POST => $adr,
['action','disconnect']);
-----
4. Reconnect after a period of time, say 5 seconds.
INSTEAD OF:
my $req = HTTP::Request->new(POST => $adr,
['action','disconnect']);
I WOULD USE:
my $req = HTTP::Request->new(POST => $adr,
----- ['action','connect']);
Since I don't know perl (nor even how to run perl on Windows XP), I wish to
ask before trying to see if the approach seems like it will work for you.
Meanwhile, I'll try to get the script to work (so far, when I click on my
modified script, see below, it just brings up Notepad).
Wilson
#!/usr/bin/perl -w
use strict;
# check out this documentation:
# first, the cookbook
# http://search.cpan.org/~gaas/libwww-perl-5.805/lwpcook.pod
# the LWP reference
# http://search.cpan.org/~gaas/libwww-perl-5.805/lib/LWP.pm
# oh but this is JUST what we want
# http://lwp.interglacial.com/ch05_05.htm
# my $adr='https://192.168.0.1/Services.asp'; # talk to this
my $adr='https://192.168.0.1/StaRouter.htm'; # talk to this
my $user='';
# my $pass='mypassword';
my $pass='letmein';
# make a User Agent
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
# make a request object
# fill in the button name and value from
# looking at the page source.
# DD-WRT puts out a complicated page with Javascript that
# I don't understand how to deal with, so this doesn't work,
# but in principle (if I knew what to put in for action and reboot)
# it should.
# my $req = HTTP::Request->new(POST => $adr,
# ['action','reboot']);
my $req = HTTP::Request->new(POST => $adr,
['action','disconnect']);
# I need to figure out how to wait 5 seconds in perl; then reconnect
my $req = HTTP::Request->new(POST => $adr,
['action','connect']);
$req->authorization_basic($user, $pass);
# send the request
my $result = $ua->request($req);
# print the result
print $result->as_string;
# The end of a perl script to run on Windows to tell the Linksys WRT54G
# router to disconnect from the ISP; then after 5 seconds, to reconnect.
------------------------------
Date: Tue, 20 Nov 2007 13:28:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Why this file download CGI works with Firefox and fails with IE ?
Message-Id: <Xns99EE562E17127asu1cornelledu@127.0.0.1>
"Petr Vileta" <stoupa@practisoft.cz> wrote in news:fhter2$2mbu$2
@ns.felk.cvut.cz:
> #############################
> try this
> open FILE, "<$loc$file" or die "Have not privileges to read?";
open my $file, '<', "$loc$file"
or die "Cannot open '$loc$file': $!";
instead of guessing the error, include $! in the error message.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
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 1044
***************************************