[28952] in Perl-Users-Digest
Perl-Users Digest, Issue: 196 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 6 03:10:18 2007
Date: Tue, 6 Mar 2007 00:09:05 -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, 6 Mar 2007 Volume: 11 Number: 196
Today's topics:
Cam::pdf, document page number <LtCommander@gmail.com>
Re: convert wikipedia to html? <ppc@cheapbooks.com>
Re: Finding Background processes? <occitan@esperanto.org>
Re: Finding Background processes? (Jamie)
get the week day of a date? <robertchen117@gmail.com>
Re: get the week day of a date? <bigiain@mightymedia.com.au>
Re: get the week day of a date? <paduille.4060.mumia.w+nospam@earthlink.net>
Re: get the week day of a date? <paduille.4060.mumia.w+nospam@earthlink.net>
Re: How to parse a string? <tadmc@augustmail.com>
Re: Is it ok to change $ENV{'QUERY_STRING'} before "use <gypark@gmail.com>
LWP::UserAgent infinite hang <balrog2000@o2.pl>
Re: LWP::UserAgent infinite hang <paduille.4060.mumia.w+nospam@earthlink.net>
new CPAN modules on Tue Mar 6 2007 (Randal Schwartz)
Re: Question about wizard Perl programmers <ayaz@dev.slash.null>
Subroutines and Callbacks in Perl/Tk <doni.sekar@gmail.com>
Re: Subroutines and Callbacks in Perl/Tk <mritty@gmail.com>
Re: Subroutines and Callbacks in Perl/Tk <ben@morrow.me.uk>
Re: Subroutines and Callbacks in Perl/Tk <paduille.4060.mumia.w+nospam@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Mar 2007 20:25:49 -0800
From: "LtCommander" <LtCommander@gmail.com>
Subject: Cam::pdf, document page number
Message-Id: <1173155149.811510.289530@c51g2000cwc.googlegroups.com>
Hi all:
I know CAM::PDF has a method to calculate the number of pages (PDF-
>numPages) in an PDF file but is there any function that can calculate
the document's starting page number.
Eg. A document consisting of 10 pages would theoretically begin at Pg.
1 and end at Pg. 10 but the relative page number (appears next to "1"
in Adobe Reader) may be (say) 91 or something. The page numbers are
relative to the previous chapter's ending page.
Is there anything out there in Perl that can return the relative
starting page number? I tried looking at many PDF modules in CPAN but
none of them seem to do this (or I don't know how to use them!)
Would be grateful for leads.
Thanks.
Vince
------------------------------
Date: 5 Mar 2007 18:58:15 -0800
From: "dt" <ppc@cheapbooks.com>
Subject: Re: convert wikipedia to html?
Message-Id: <1173149895.593992.101820@j27g2000cwj.googlegroups.com>
> Huh? It *is* html as it comes. Just save it.
>
> Anno
Wikipedia uses a custom format that is NOT html. I am not referring to
their page as browsed on the web, but from their backend API.
it needs to be converted to html/.
------------------------------
Date: Tue, 06 Mar 2007 00:15:08 +0100
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: Finding Background processes?
Message-Id: <esi8ph$545$03$1@news.t-online.com>
la 24.02.2007 13:40 Jamie skribis:
> Depends on the platform, my personal favorite is to create a broken
> symlink containing the process ID, something like this:
>
> while(! symlink($$,$FLAG)){
>
> I don't know why I perfer to cram the info into a symlink, guess it's a habit. Most
> people seem to use pid files. Far as I know, both are equally valid methods, symlinks
> aren't portable though. You do need something that is "atomic" for the flag creation,
> open(FH,">pidfile") is not a good choice since it'll happily clobber a brother who
> managed to squeak in on a time slice.
I also prefer symlinks for pids. They're much less of a hassle than
open/flock/print/close and I can see them instantly with ls.
best regards
Daniel
------------------------------
Date: Tue, 06 Mar 2007 00:56:05 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: Finding Background processes?
Message-Id: <Lc117312271272680x8c22b48@pong.podro.com>
In <esi8ph$545$03$1@news.t-online.com>,
Daniel Pfeiffer <occitan@esperanto.org> mentions:
>la 24.02.2007 13:40 Jamie skribis:
>
>> Depends on the platform, my personal favorite is to create a broken
>> symlink containing the process ID, something like this:
>>
>> while(! symlink($$,$FLAG)){
>>
>> I don't know why I perfer to cram the info into a symlink, guess it's a habit. Most
>> people seem to use pid files. Far as I know, both are equally valid methods, symlinks
>> aren't portable though. You do need something that is "atomic" for the flag creation,
>> open(FH,">pidfile") is not a good choice since it'll happily clobber a brother who
>> managed to squeak in on a time slice.
>
>I also prefer symlinks for pids. They're much less of a hassle than
>open/flock/print/close and I can see them instantly with ls.
I recall Matt Dillon from DragonFlyBSD claiming that, if you open a lock file with
the O_CREAT option, you don't need to lock it. (the subject at hand was NFS
and locking) But, I still like to use a symlink. :-)
flock, even with perl, does not work when flocking NFS filesystems between linux
and dragonflybsd. (this took me by surprise, I had thought perl's flock implementation
had "magic" to get around this, it didn't when I tried it.)
Jamie
--
http://www.geniegate.com Custom web programming
Perl * Java * UNIX User Management Solutions
------------------------------
Date: 5 Mar 2007 21:30:48 -0800
From: "robertchen117@gmail.com" <robertchen117@gmail.com>
Subject: get the week day of a date?
Message-Id: <1173159048.104179.206560@v33g2000cwv.googlegroups.com>
my date format is "030207", 03/02/2007, how could I get it is Friday?
Thanks, too tricky for me and beyond my mind.
------------------------------
Date: Tue, 06 Mar 2007 17:41:57 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: get the week day of a date?
Message-Id: <bigiain-E543E2.17415706032007@news.usenetmonster.com>
In article <1173159048.104179.206560@v33g2000cwv.googlegroups.com>,
"robertchen117@gmail.com" <robertchen117@gmail.com> wrote:
> my date format is "030207", 03/02/2007, how could I get it is Friday?
>
> Thanks, too tricky for me and beyond my mind.
have a read of:
perldoc -f localtime
and
perldoc Time::Local
They'll explain to you how this works:
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my @days=qw(Sun Mon Tue Wed Thu Fri Sat);
# note: months start from 0, so march is 02
# I get timeFromEpoch at midday so daylight savings changes won't matter
my $timeFromEpoch=Time::Local::timelocal(00,00,12,02,02,2007);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
=localtime($ timeFromEpoch);
print $days[$wday];
--
"Everything you love, everything meaningful with depth and history,
all passionate authentic experiences will be appropriated, mishandled,
watered down, cheapened, repackaged, marketed and sold to the people
you hate." Mr Jalopy quoting Hooptyrides (on jalopyjunktown.com)
------------------------------
Date: Tue, 06 Mar 2007 07:17:41 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: get the week day of a date?
Message-Id: <pA8Hh.9564$Jl.9122@newsread3.news.pas.earthlink.net>
On 03/05/2007 11:30 PM, robertchen117@gmail.com wrote:
> my date format is "030207", 03/02/2007, how could I get it is Friday?
>
> Thanks, too tricky for me and beyond my mind.
>
You can use the strftime function from the POSIX module.
------------------------------
Date: Tue, 06 Mar 2007 07:24:32 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: get the week day of a date?
Message-Id: <QG8Hh.9755$tD2.2010@newsread1.news.pas.earthlink.net>
On 03/06/2007 01:17 AM, Mumia W. wrote:
> On 03/05/2007 11:30 PM, robertchen117@gmail.com wrote:
>> my date format is "030207", 03/02/2007, how could I get it is Friday?
>>
>> Thanks, too tricky for me and beyond my mind.
>>
>
> You can use the strftime function from the POSIX module.
>
>
Here's a short example:
require POSIX;
import POSIX qw(strftime);
my $string = '030207';
my @date = $string =~ /../g;
$date[2] += 100;
$date[0] -= 1;
print strftime('%F (%A)',0,0,0,@date[1,0,2]), "\n";
------------------------------
Date: Mon, 5 Mar 2007 18:45:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to parse a string?
Message-Id: <slrneuped2.q8h.tadmc@tadmc30.august.net>
snoopy_@excite.com <snoopy_@excite.com> wrote:
> And I want to count all the instances of "GE" how can I do this?
If the string is in $_, then:
my $count = s/GE/GE/g;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Mar 2007 23:51:50 -0800
From: "Raymundo" <gypark@gmail.com>
Subject: Re: Is it ok to change $ENV{'QUERY_STRING'} before "use CGI;" is called..?
Message-Id: <1173167510.298794.171750@v33g2000cwv.googlegroups.com>
Thank you, Anno and Ben.
Anno's suggestion:
my $param = $q->Vars;
$_ = check_and_convert( $_) for values %$param;
works well with GET request. But it makes a problem with POST request
like file-uploading. I don't know why. I just guess it's because
check_and_convert affects the contents of POST request. (If I comment
out check_and_convert line, script works well)
I'm interested in only GET request, because POST request includes
"charset=" field in its header and I can convert, if needed, the
encoding of the contents. So I'm planning to add if clause:
if ($q->request_method() eq "GET") {
my $param = $q->Vars;
$_ = check_and_convert( $_) for values %$param;
}
Ben, would you please tell me why Encode::Guess isn't safe? Does it
have a security problem?
Anyway,
> For a (detailed) explanation of details of I18N form submission, see
> http://xrl.us/u68e. Executive summary: serve forms as 'text/html;
> charset=utf-8' and assume the results are in UTF-8.
The script does so when it prints forms and receives POST data from
the forms, which seemed to be doing well.
The problem is related to GET request, that is, when URL includes
multi-bytes characters. W3C recommends that multi-bytes chars in URL
should be %-encoded. (http://www.w3.org/TR/REC-html40/interact/
forms.html#form-content-type) But I still want to support when
visitors type URL using their fingers (they would not like to type "%EC
%90.." :-) and when other webpage gives a link to my page not using %-
encoded string.
...
Returing to my first post in this thread... Is it so bad idea to
change the environment variable QUERY_STRING? It solves every problem
about this. It requires only one additional line in code. I think that
change may affect only the script and its child processes, and the
script doesn't fork any child process.
Raymundo at South Korea.
------------------------------
Date: Tue, 06 Mar 2007 00:18:18 +0100
From: Tomek <balrog2000@o2.pl>
Subject: LWP::UserAgent infinite hang
Message-Id: <op.toqocss7bdw0a5@balrog>
Hello!
I use Perl 5.8.8 and newest LWP.
Recently, I encountered some weird behavior using LWP::UserAgent. LWP
makes 100% CPU time with this
simple script and hangs up. Seems remote server is
sending bad HTTP response, is there a way to solve it ?
adding $ua->max_size(xx) doesn't help.
If you have any idea how to solve that please tell me..
Best regards, Tomasz Kraus
Error can be reproduced with code:
#!/usr/local/bin/perl
use strict;
use LWP::UserAgent;
my $ua=new LWP::UserAgent;
$ua->timeout(30);
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 1.1.4322)");
push @{ $ua->requests_redirectable }, 'POST';
my
$resp=$ua->get('http://cod.menofgod.us/user.php?op=register&module=NS-NewUser');
if ($resp->is_success) {
print $resp->content;
}
print $resp->content;
------------------------------
Date: Tue, 06 Mar 2007 04:50:02 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: LWP::UserAgent infinite hang
Message-Id: <_p6Hh.9541$Jl.519@newsread3.news.pas.earthlink.net>
On 03/05/2007 05:18 PM, Tomek wrote:
> Hello!
>
> I use Perl 5.8.8 and newest LWP.
>
> Recently, I encountered some weird behavior using LWP::UserAgent. LWP
> makes 100% CPU time with this
> simple script and hangs up. Seems remote server is
> sending bad HTTP response, is there a way to solve it ?
>
> adding $ua->max_size(xx) doesn't help.
>
> If you have any idea how to solve that please tell me..
>
>
> Best regards, Tomasz Kraus
>
> Error can be reproduced with code:
>
> #!/usr/local/bin/perl
> use strict;
> use LWP::UserAgent;
> my $ua=new LWP::UserAgent;
> $ua->timeout(30);
> $ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
> CLR 1.1.4322)");
> push @{ $ua->requests_redirectable }, 'POST';
> my
> $resp=$ua->get('http://cod.menofgod.us/user.php?op=register&module=NS-NewUser');
>
> if ($resp->is_success) {
> print $resp->content;
> }
> print $resp->content;
Perhaps it's a defense mechanism. Most websites take a dim view of
people using automated methods to create potentially hundreds of user
accounts.
------------------------------
Date: Tue, 6 Mar 2007 05:42:08 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Tue Mar 6 2007
Message-Id: <JEGvu8.17EI@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-SDUM-Renew-0.01
http://search.cpan.org/~root/Acme-SDUM-Renew-0.01/
Renew your books from www.sdum.uminho.pt
----
BDB-0.1
http://search.cpan.org/~mlehmann/BDB-0.1/
Asynchronous Berkeley DB access
----
Bio-Grep-v0.0.1
http://search.cpan.org/~limaone/Bio-Grep-v0.0.1/
Perl extension for searching in Fasta files
----
Bio-Grep-v0.0.2
http://search.cpan.org/~limaone/Bio-Grep-v0.0.2/
Perl extension for searching in Fasta files
----
CAS-0.87
http://search.cpan.org/~seanq/CAS-0.87/
Central Authorization Server
----
CAS-Apache-0.44
http://search.cpan.org/~seanq/CAS-Apache-0.44/
The great new CAS::Apache!
----
CPAN-1.88_78
http://search.cpan.org/~andk/CPAN-1.88_78/
query, download and build perl modules from CPAN sites
----
Cache-Memcached-Indexable-0.01
http://search.cpan.org/~taniguchi/Cache-Memcached-Indexable-0.01/
A key indexable Cache::Memcached wrapper
----
Cache-Memcached-Indexable-0.02
http://search.cpan.org/~taniguchi/Cache-Memcached-Indexable-0.02/
A key indexable Cache::Memcached wrapper
----
Callback-1.07
http://search.cpan.org/~muir/Callback-1.07/
object interface for function callbacks
----
DBIx-Class-DigestColumns-0.04000
http://search.cpan.org/~groditi/DBIx-Class-DigestColumns-0.04000/
Automatic digest columns
----
DBIx-Class-InflateColumn-Currency-0.01
http://search.cpan.org/~claco/DBIx-Class-InflateColumn-Currency-0.01/
Auto-create Data::Currency objects from columns.
----
Data-Currency-0.03
http://search.cpan.org/~claco/Data-Currency-0.03/
Container class for currency conversion/formatting
----
Data-Serializer-0.38
http://search.cpan.org/~neely/Data-Serializer-0.38/
Modules that serialize data structures
----
Data-Serializer-0.39
http://search.cpan.org/~neely/Data-Serializer-0.39/
Modules that serialize data structures
----
Date-Holidays-0.12
http://search.cpan.org/~jonasbn/Date-Holidays-0.12/
a Date::Holidays::* OOP Adapter aggregator
----
DateTime-Locale-0.34
http://search.cpan.org/~drolsky/DateTime-Locale-0.34/
Localization support for DateTime.pm
----
Egg-Model-DBIC-0.05
http://search.cpan.org/~lushe/Egg-Model-DBIC-0.05/
DBIx::Class for Egg.
----
Egg-Release-1.15
http://search.cpan.org/~lushe/Egg-Release-1.15/
WEB application framework release version.
----
Egg-Release-1.16
http://search.cpan.org/~lushe/Egg-Release-1.16/
WEB application framework release version.
----
Geo-Coordinates-UTM-XS-0.01
http://search.cpan.org/~salva/Geo-Coordinates-UTM-XS-0.01/
C/XS reimplementation of Geo::Coordinates::UTM
----
IO-Async-0.02
http://search.cpan.org/~pevans/IO-Async-0.02/
a collection of modules that implement asynchronous filehandle IO
----
LaTeX-Table-v0.0.3
http://search.cpan.org/~limaone/LaTeX-Table-v0.0.3/
Perl extension for the automatic generation of LaTeX tables.
----
Mail-Audit-2.217
http://search.cpan.org/~rjbs/Mail-Audit-2.217/
Library for creating easy mail filters
----
Math-Units-PhysicalValue-0.68
http://search.cpan.org/~jettero/Math-Units-PhysicalValue-0.68/
An object oriented interface for handling values with units.
----
Module-Install-0.65
http://search.cpan.org/~adamk/Module-Install-0.65/
Standalone, extensible Perl module installer
----
Net-SMS-Optimus-0.02
http://search.cpan.org/~root/Net-SMS-Optimus-0.02/
Send SMS through www.optimus.pt
----
PITA-Test-Dummy-Perl5-MI-0.65_01
http://search.cpan.org/~adamk/PITA-Test-Dummy-Perl5-MI-0.65_01/
CPAN Test Dummy for testing Module::Install::With
----
PPI-1.199_02
http://search.cpan.org/~adamk/PPI-1.199_02/
Parse, Analyze and Manipulate Perl (without perl)
----
Perl-MinimumVersion-0.14
http://search.cpan.org/~adamk/Perl-MinimumVersion-0.14/
Find a minimum required version of perl for Perl code
----
RRD-Simple-1.43
http://search.cpan.org/~nicolaw/RRD-Simple-1.43/
Simple interface to create and store data in RRD files
----
Search-Xapian-0.9.10.0
http://search.cpan.org/~olly/Search-Xapian-0.9.10.0/
Perl XS frontend to the Xapian C++ search library.
----
Set-IntSpan-Island-0.01
http://search.cpan.org/~martink/Set-IntSpan-Island-0.01/
extension for Set::IntSpan to handle islands and covers
----
Sys-Statistics-Linux-0.09_07
http://search.cpan.org/~bloonix/Sys-Statistics-Linux-0.09_07/
Collect linux system statistics.
----
Sys-Statistics-Linux-0.09_08
http://search.cpan.org/~bloonix/Sys-Statistics-Linux-0.09_08/
Collect linux system statistics.
----
TAPx-Parser-0.50_07
http://search.cpan.org/~ovid/TAPx-Parser-0.50_07/
Parse TAP output
----
Thread-Pool-Simple-0.01
http://search.cpan.org/~jwu/Thread-Pool-Simple-0.01/
A simple thread-pool implementation
----
WWW-Zorpia-Upload-0.01
http://search.cpan.org/~fayland/WWW-Zorpia-Upload-0.01/
upload photos to www.zorpia.com
----
XML-MyXML-0.092
http://search.cpan.org/~karjala/XML-MyXML-0.092/
A simple XML module
----
XML-MyXML-0.093
http://search.cpan.org/~karjala/XML-MyXML-0.093/
A simple-to-use XML module, for parsing and creating XML documents
----
XML-RSS-FromHTML-Simple-0.01
http://search.cpan.org/~mschilli/XML-RSS-FromHTML-Simple-0.01/
Create RSS feeds for sites that don't offer them
----
Youri-BTS-v0.1.0
http://search.cpan.org/~grousse/Youri-BTS-v0.1.0/
----
Youri-Config-v0.1.0
http://search.cpan.org/~grousse/Youri-Config-v0.1.0/
Youri configuration handler
----
Youri-Media-v0.1.0
http://search.cpan.org/~grousse/Youri-Media-v0.1.0/
Abstract media class
----
Youri-Package-RPM-Generator-v0.1.0
http://search.cpan.org/~grousse/Youri-Package-RPM-Generator-v0.1.0/
Template-based rpm generator
----
Youri-Repository-v0.1.0
http://search.cpan.org/~grousse/Youri-Repository-v0.1.0/
Abstract repository
----
Youri-Utils-v0.1.0
http://search.cpan.org/~grousse/Youri-Utils-v0.1.0/
Youri shared functions
----
onto-perl-0.29
http://search.cpan.org/~easr/onto-perl-0.29/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 06 Mar 2007 11:31:37 +0500
From: Ayaz Ahmed Khan <ayaz@dev.slash.null>
Subject: Re: Question about wizard Perl programmers
Message-Id: <pan.2007.03.06.06.31.34.425998@dev.slash.null>
"De Vliegende Hollander" typed:
> The sentient life form Ayaz Ahmed Khan posted the following:
>> I find Python much more fun to code in than Perl. I have been coding in
>> Perl longer than in Python, though, but having dived into Pythonic waters
>> (so to speak), I prefer Python over Perl whenever I have the room to do
>> so.
>
> But it's not nearly as powerful as Perl...
That is pretty subjective: what makes a language powerful?
--
Ayaz Ahmed Khan
Falling in love makes smoking pot all day look like the ultimate in
restraint.
-- Dave Sim, author of "Cerebus".
------------------------------
Date: 5 Mar 2007 16:19:33 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Subroutines and Callbacks in Perl/Tk
Message-Id: <1173140373.547676.307290@q40g2000cwq.googlegroups.com>
Hi,
I am right now learning about Perl/TK and have a basic question
regarding subroutines and callbacks.
I was wondering how can I have the subroutine output to display in the
MainWindow if the subroutine is called using a button widget from the
MainWindow.
Here is the code that I wrote to test my above question.
#!/usr/bin/perl
use strict;
use Tk;
my $mw = MainWindow->new;
$mw->title("Demo Program");
$mw->Button(-text => "Test",
-command => sub{test()})->pack;
$mw->Button(-text => "Exit",
-command => sub{exit})->pack;
MainLoop;
sub test {
print "We have reached the subroutine part \n";
}
>From the above code, I wanted the print statement "We have reached the
subroutine part" to display in the MainWindow when I press the "test"
button.
When I press the "Test" button the result is getting displayed on the
command line and not on the MainWindow.
Thanks,
doni
------------------------------
Date: 5 Mar 2007 17:28:44 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Subroutines and Callbacks in Perl/Tk
Message-Id: <1173144524.011919.275520@s48g2000cws.googlegroups.com>
On Mar 5, 7:19 pm, "doni" <doni.se...@gmail.com> wrote:
> Hi,
>
> I am right now learning about Perl/TK and have a basic question
> regarding subroutines and callbacks.
>
> I was wondering how can I have the subroutine output to display in the
> MainWindow if the subroutine is called using a button widget from the
> MainWindow.
>
> Here is the code that I wrote to test my above question.
>
> #!/usr/bin/perl
>
> use strict;
> use Tk;
>
> my $mw = MainWindow->new;
> $mw->title("Demo Program");
> $mw->Button(-text => "Test",
> -command => sub{test()})->pack;
> $mw->Button(-text => "Exit",
> -command => sub{exit})->pack;
> MainLoop;
>
> sub test {
> print "We have reached the subroutine part \n";
>
> }
> >From the above code, I wanted the print statement "We have reached the
>
> subroutine part" to display in the MainWindow when I press the "test"
> button.
>
> When I press the "Test" button the result is getting displayed on the
> command line and not on the MainWindow.
You are very confused about what Perl/Tk is. It is not a different
kind of Perl. All the functions that you learned in Perl do *exactly*
what they do when you `use Tk;`. Nothing's changed. print() still
prints to standard output.
If you want to put a message in your MainWindow, create a Label widget
in the main window, with a -textvariable attribute. Then when you
push the test button, change the contents of that variable.
Paul Lalli
------------------------------
Date: Tue, 6 Mar 2007 03:48:20 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Subroutines and Callbacks in Perl/Tk
Message-Id: <4t4vb4-rnb.ln1@osiris.mauzo.dyndns.org>
Quoth "Paul Lalli" <mritty@gmail.com>:
> On Mar 5, 7:19 pm, "doni" <doni.se...@gmail.com> wrote:
> >
> > I was wondering how can I have the subroutine output to display in the
> > MainWindow if the subroutine is called using a button widget from the
> > MainWindow.
> >
[ snip code ]
> >
> > When I press the "Test" button the result is getting displayed on the
> > command line and not on the MainWindow.
>
> You are very confused about what Perl/Tk is. It is not a different
> kind of Perl. All the functions that you learned in Perl do *exactly*
> what they do when you `use Tk;`. Nothing's changed. print() still
> prints to standard output.
>
> If you want to put a message in your MainWindow, create a Label widget
> in the main window, with a -textvariable attribute. Then when you
> push the test button, change the contents of that variable.
You may find the following useful: it's what I use to give a basically
command-line program a simple GUI.
Usage is as
#!/usr/bin/perl
use BMORROW::Tie::TkWatch qw/Run/;
Run {
print "Hello world!\n";
warn "Houston, we have a problem";
} 'My Perl App';
__END__
I call the module BMORROW::Tie::TkWatch (I have a convention that
modules for my own use are prefixed with my CPAN id); you probably want
to call it something else.
Ben
package BMORROW::Tie::TkWatch;
use warnings;
use strict;
our @EXPORT_OK = qw/Run Dialog Update/;
use base qw/Exporter/;
use Tk;
use Tk::Dialog;
use Scalar::Util qw/openhandle/;
my %TK;
$TK{mw} = Tk::MainWindow->new(
-title => 'Perl',
);
$TK{font} = $TK{mw}->Font(
-family => 'Bitstream Vera Sans Mono',
-size => 10,
);
$TK{out} = $TK{mw}->Scrolled(
ROText =>
-font => $TK{font},
-width => 80,
-height => 35,
-scrollbars => 'osoe',
)->pack(
-fill => 'both',
-expand => 'y',
);
$TK{out}->tag(configure => out => -foreground => 'black');
$TK{out}->tag(configure => err => -foreground => 'red');
$TK{out}->focus;
sub TIEHANDLE {
my $c = shift;
return bless \@_, $c;
}
sub PRINT {
my $s = shift;
my ($o, $t, $h) = @$s;
my $txt = do {
no warnings 'uninitialized';
(join $,, @_) . $\
};
openhandle $h and print $h $txt;
$o->insert(end => $txt, $t);
$o->see('end');
$o->update;
}
tie *STDOUT, __PACKAGE__, $TK{out}, 'out';
open my $OERR, '>&', \*STDERR;
tie *STDERR, __PACKAGE__, $TK{out}, 'err', $OERR;
sub Run (&$) {
my $sub = shift;
$TK{mw}->configure(-title => shift);
$TK{mw}->after(0, $sub);
Tk::MainLoop;
}
sub Dialog {
my $ans = $TK{mw}->Dialog(@_)->Show();
$TK{mw}->update;
return $ans;
}
sub Update {
$TK{mw}->update;
}
sub Tk::Error {
my ($mw, $err) = @_;
print STDERR $err;
}
1;
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Tue, 06 Mar 2007 04:50:03 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Subroutines and Callbacks in Perl/Tk
Message-Id: <%p6Hh.9542$Jl.3718@newsread3.news.pas.earthlink.net>
On 03/05/2007 06:19 PM, doni wrote:
> Hi,
>
> I am right now learning about Perl/TK and have a basic question
> regarding subroutines and callbacks.
>
> I was wondering how can I have the subroutine output to display in the
> MainWindow if the subroutine is called using a button widget from the
> MainWindow.
>
> Here is the code that I wrote to test my above question.
>
> #!/usr/bin/perl
>
> use strict;
> use Tk;
>
> my $mw = MainWindow->new;
> $mw->title("Demo Program");
> $mw->Button(-text => "Test",
> -command => sub{test()})->pack;
> $mw->Button(-text => "Exit",
> -command => sub{exit})->pack;
> MainLoop;
>
> sub test {
> print "We have reached the subroutine part \n";
> }
>
>>From the above code, I wanted the print statement "We have reached the
> subroutine part" to display in the MainWindow when I press the "test"
> button.
>
> When I press the "Test" button the result is getting displayed on the
> command line and not on the MainWindow.
>
> Thanks,
> doni
>
Create a label or something else to display the text and store the
reference to it. When you need to display something in that label,
change its text:
use strict;
use Tk;
my $mw = MainWindow->new;
$mw->title("Demo Program");
$mw->Button(-text => "Test",
-command => sub{testfunc()})->pack;
my $lbl = $mw->Label(-text => '')->pack;
$mw->Button(-text => "Exit",
-command => sub{exit})->pack;
MainLoop();
sub testfunc {
my $msg = $lbl->cget('-text');
$lbl->configure(-text => $msg . "We have reached the subroutine
part.\n");
}
__HTH__
------------------------------
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 196
**************************************