[23072] in Perl-Users-Digest
Perl-Users Digest, Issue: 5293 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 30 18:06:02 2003
Date: Wed, 30 Jul 2003 15:05:11 -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 Wed, 30 Jul 2003 Volume: 10 Number: 5293
Today's topics:
Re: Anyone build the Berkeley DBXML library for AS and (Bob)
Camel ecards for Perl lovers (Edouard Lagache)
Can Perl be used for this? <giecie@hotmail.com>
Re: Can Perl be used for this? <jaspax@u.washington.edu>
Re: Can Perl be used for this? (Tad McClellan)
Re: CGI.pm problem under Redhat Linux 9.0 (perl-5.8.0) (Larry James)
Re: Converting from decimal to hex <trammell+usenet@hypersloth.invalid>
Re: Converting from decimal to hex <anders@XXX.redakula.net>
Re: failed /g match on empty string does not reset pos( <grazz@pobox.com>
getting complete file listings in perl c@msn.com
Re: help with file dialog (Go Perl)
Re: help with file dialog <mgarrish@rogers.com>
Re: How do you Call a Perl subroutine with a variable n <nobull@mail.com>
Irreproducible bug while using the debugger <jaspax@u.washington.edu>
Re: LWP::Request <int.consultNOCAPITALS@macmail.com>
Re: LWP::Request <NOSPAM@bigpond.com>
LWP::Simple and authentication (reggie)
Re: LWP::Simple and authentication <glex_nospam@qwest.net>
Re: LWP::Simple and authentication <NOSPAM@bigpond.com>
Re: Perl - how to compute totals via hash request <krahnj@acm.org>
Perl Objects (Paul)
Re: Perl Objects <bart.lateur@pandora.be>
Re: Perl training resources? <stevea@wrq.com>
perl/tk back end questions (Go Perl)
printing out the values of variables in a previous stac <mlwp@pacbell.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Jul 2003 09:11:40 -0700
From: bobx@linuxmail.org (Bob)
Subject: Re: Anyone build the Berkeley DBXML library for AS and Windows?
Message-Id: <1001ff04.0307300811.5f4e229@posting.google.com>
Kevin Michael Vail <kevin@vaildc.net> wrote in message news:<kevin-FCCE6C.21545429072003@vienna7.his.com>...
> In article <1001ff04.0307290651.a57c8b4@posting.google.com>,
> bobx@linuxmail.org (Bob) wrote:
>
> > I am on Windows and do not have a compiler. Had anyone compiled the
> > Berkeley DBXML library for Windows? I would like to try out DBXML.
>
> The library itself is available as a binary download from SleepyCat.
> Dunno about using it with Perl, though.
I have the binary for Windows but not the Perl stuff needed.
Bob
------------------------------
Date: 30 Jul 2003 11:33:25 -0700
From: elagache@yahoo.com (Edouard Lagache)
Subject: Camel ecards for Perl lovers
Message-Id: <a90aa8bf.0307301033.5fb2d730@posting.google.com>
Dear Perl user community:
I have developed a GPL Perl-based ecard application: Penguin Greetings
and have created some ecards based on photos I took at the June Camel
Races in Benicia this year. So I offer to the Perl community ecards
with a suitable camel motif:
http://www.canebas.org/pgreet.scgi?site=PgCamel
Unfortunately my demonstration server has a very limited bandwidth, so
I humbly beg my fellow Perl-o-philes to consider downloading and
installing Penguin Greetings on some server with a larger pipe. For
more information on Penguin Greetings visit its SourceForge home at:
http://pgreet.sourceforge.net/
Cheers!
Edouard Lagache
Lead Developer, Penguin Greetings
http://pgreet.sourceforge.net/
------------------------------
Date: Wed, 30 Jul 2003 20:04:54 +0200
From: GC <giecie@hotmail.com>
Subject: Can Perl be used for this?
Message-Id: <3F2808C6.7020006@hotmail.com>
Hi,
I'm looking for a solution to capture the data on a web page with 2
buttons, send & receive threads of this URL
http://atlantis.b-rail.be:8880/atlantis/SilverStream/Pages/PM_GalileoLog.html.
It would be nice to gather both pages and dump them into a MySql database.
Do you think Perl would be suitable for this and what's the direction I
need to take to build this script?
Geert
------------------------------
Date: Wed, 30 Jul 2003 14:02:55 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Can Perl be used for this?
Message-Id: <Pine.A41.4.56.0307301400510.97420@dante52.u.washington.edu>
GC sikyal:
> Hi,
>
> I'm looking for a solution to capture the data on a web page with 2
> buttons, send & receive threads of this URL
> http://atlantis.b-rail.be:8880/atlantis/SilverStream/Pages/PM_GalileoLog.html.
> It would be nice to gather both pages and dump them into a MySql database.
> Do you think Perl would be suitable for this and what's the direction I
> need to take to build this script?
Start with:
use WWW::Mechanize;
use DBI;
Find their docs on CPAN and have fun.
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
------------------------------
Date: Wed, 30 Jul 2003 16:29:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can Perl be used for this?
Message-Id: <slrnbige59.8b2.tadmc@magna.augustmail.com>
GC <giecie@hotmail.com> wrote:
> I'm looking for a solution to capture the data on a web page with 2
> buttons,
How do I automate an HTML form submission?
> send & receive threads of this URL
Huh? What does "threads" mean when you say it?
Maybe you want to fetch the resource identified by some URL?
How do I fetch an HTML file?
Maybe you need to find URLs in text?
How do I extract URLs?
All of those indented questions above are from the Perl FAQ.
You are expected to check the Perl FAQ *before* posting to
the Perl newsgroup.
So you should have tried some applicable keywords already such as
"HTML" and "URL", then you would have already seen the answers
that are there. You can use the perldoc program to do keyword searches:
perldoc -q HTML
> http://atlantis.b-rail.be:8880/atlantis/SilverStream/Pages/PM_GalileoLog.html.
> It would be nice to gather both pages and dump them into a MySql database.
> Do you think Perl would be suitable for this
Sure.
I do stuff like that all of the time.
> and what's the direction I
> need to take to build this script?
Use the LWP module:
perldoc lwpcook
http://search.cpan.org/author/GAAS/libwww-perl-5.69/
and perhaps
http://search.cpan.org/author/PETDANCE/WWW-Mechanize-0.56/
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Jul 2003 08:11:57 -0700
From: ljames@apollo3.com (Larry James)
Subject: Re: CGI.pm problem under Redhat Linux 9.0 (perl-5.8.0)
Message-Id: <b53cbdef.0307300711.4cf2f36e@posting.google.com>
"marmot101" <marmot101@yahoo.com> wrote in message news:<x%yTa.27$RO2.48847@news.uswest.net>...
> Hi,
>
> I just installed Redhat Linux 9.0, which include perl-5.8.0. However, when I
> run a perl program begin with:
> use CGI /:standard/;
>
> System complains: Can not locate CGI.pm ...
>
> I went to perl directory: /usr/lib/perl5/5.8.0. There is no CGI.pm, but
> there is a CGI.pm.newcgi. What should I do? rename this CGI.pm.newcgi to
> CGI.pm? that sounds weird ...
>
> Anyone can give me some suggestion?
>
> Thanks!
Marmot, I guess since no one mentioned anything about the
CGI.pm.newcgi, no one here knows whot to do with them. I still
wonder.
Anyway, the fix for your problem is to install CGI. You can do
that by using the cpan suggestions given to you by Dan.
"perl -MCPAN -e shell" and then "install CGI".
-- L. James
------------------
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
------------------------------
Date: Wed, 30 Jul 2003 15:14:51 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Converting from decimal to hex
Message-Id: <slrnbifo7b.9ef.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Wed, 30 Jul 2003 16:31:47 +0200, Anders Bystrup
<anders@XXX.redakula.net> wrote:
> Hi.
>
> I have an array consisting of mac addresses in decimal form seperated by :
> Like this:
> 0:0:33:195:37:6 0:0:180:75:15:17 and so on
>
> I now need to convert the decimal numbers into hex on the following form:
> 00:e0:98:9b:ce:6f 00:e0:98:a4:db:41
>
> Is it possible to do this using a search and replace or how would you do
> this?
>
One solution:
s/(\d+)/sprintf("%02x",$1)/eg;
------------------------------
Date: Wed, 30 Jul 2003 18:29:23 +0200
From: "Anders Bystrup" <anders@XXX.redakula.net>
Subject: Re: Converting from decimal to hex
Message-Id: <pan.2003.07.30.16.29.21.105782@XXX.redakula.net>
On Wed, 30 Jul 2003 15:14:51 +0000, John J. Trammell wrote:
> On Wed, 30 Jul 2003 16:31:47 +0200, Anders Bystrup
> <anders@XXX.redakula.net> wrote:
>> Hi.
>>
>> I have an array consisting of mac addresses in decimal form seperated by
>> : Like this:
>> 0:0:33:195:37:6 0:0:180:75:15:17 and so on
>>
>> I now need to convert the decimal numbers into hex on the following
>> form: 00:e0:98:9b:ce:6f 00:e0:98:a4:db:41
>>
>> Is it possible to do this using a search and replace or how would you do
>> this?
>>
>>
> One solution:
>
> s/(\d+)/sprintf("%02x",$1)/eg;
Thanks!
That was what it took!
/Anders
------------------------------
Date: Wed, 30 Jul 2003 18:45:36 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: failed /g match on empty string does not reset pos()
Message-Id: <knUVa.1677$cI2.46@nwrdny01.gnilink.net>
David Bouman <dbo@xbn.nl> wrote:
> Steve Grazzini wrote:
>> More generally, it looks like the "target is too short"
>> optimization isn't resetting pos().
>
> Ok so it *is* a bug then. Has somebody filed a report yet?
I was going to leave that honor to you. :-)
By the way, you can browse/search the bug database:
http://xrl.us/npd [ a search for "pos(" ]
I couldn't find anything directly related.
--
Steve
------------------------------
Date: Wed, 30 Jul 2003 13:50:13 -0700
From: c@msn.com
Subject: getting complete file listings in perl
Message-Id: <mvagivo75i0cbmlffunuun215lkrv4vv45@4ax.com>
I'm stuck in trying to get a list of files through use of a perl script running locally on a windows
machine.
What I'd like to see is something like:
------------------------
tutorial <DIR> 07-12-03 11:00p tutorial
work <DIR> 07-19-03 10:00p work
activepe msi 8,852,456 03-30-03 7:22p ActivePerl-5.6.1.635-MSWin32-x86.msi
dirtest pl 201 07-28-03 7:30p dirtest.pl
output txt 0 07-28-03 7:24p output.txt
perldata htm 34,203 07-12-03 11:09p Perl Data Structures Cookbook.html
---------------------
which I can get by backticking this way:
@dirlist= `dir /a /s`;
The problem arises from the fact that windows will not allow many kinds of files to be visible in
either windows itself or DOS.
As a test case, I'm trying to get a listing of the tree below c:\windows\temporary internet files\
on the assumption that if I can get that accurately, I'll have accuracy elsewhere.
Most of the win32 interface stuff like file::glob and suchlike miss some of these files and fail to
get size & date info in one pass.
Does anyone know how to do this without having to write a standalone pure DOS app to be called to
get a listing?
thanx for any assistance, and please reply here as I'm having a spam problem also :(
------------------------------
Date: 30 Jul 2003 09:33:37 -0700
From: puissant00@yahoo.com (Go Perl)
Subject: Re: help with file dialog
Message-Id: <d3825316.0307300833.1716c472@posting.google.com>
It is working fine i am now able to see the file directory and stuff
but when i click on the file and say accept.i cannot see it in the
text box. Is there any short way to select a file and send it as an
input to a perl algorithm run by separate program instead of going
throught this
"mgarrish" <mgarrish@rogers.com> wrote in message news:<2lHVa.12052$rsJ.10892@news04.bloor.is.net.cable.rogers.com>...
> "Go Perl" <puissant00@yahoo.com> wrote in message
> news:d3825316.0307290829.35a72bc3@posting.google.com...
> >
> > sub fileDialog {
> > my $w = shift;
> > my $ent = shift;
> > my $operation = shift;
> > my $types;
> > my $file;
> > @types =
> > (["Text files", '*.txt'],
> > ["All files", '*']
> > );
> > if ($operation eq 'open') {
> > $file = $w->getOpenFile(-filetypes => \@types);
> > }
> > }
>
> This is the subroutine that gets called when you click on the Browse
> buttons, but you have nothing in here to open a file selector window.
> Further, you send the operation types 'one', 'two', three' and 'four', which
> means that it winds up doing nothing (since only 'open' will trigger your if
> condition). If you just want to see a file selector, add the following after
> the if statement:
>
> else {
> $FSref = $w->FileSelect(-directory => 'c:\\');
> $file = $FSref->Show;
> }
>
> It takes a few minutes to open the FileSelect window on my computer, but it
> does show up eventually (your script is not hanging on you).
>
> Matt
------------------------------
Date: Wed, 30 Jul 2003 19:25:24 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: help with file dialog
Message-Id: <EYUVa.1628$4UE.344@news01.bloor.is.net.cable.rogers.com>
"Go Perl" <puissant00@yahoo.com> wrote in message
news:d3825316.0307300833.1716c472@posting.google.com...
> It is working fine i am now able to see the file directory and stuff
> but when i click on the file and say accept.i cannot see it in the
> text box. Is there any short way to select a file and send it as an
> input to a perl algorithm run by separate program instead of going
> throught this
>
>
Once you select the file, it is stored in the variable $file. If you want to
update the entry box, you have to add a configure command to do so (the two
are not inter-related, as you should have noticed when you created them
separately). Changing the else condition to the following should make it do
what you want:
else {
$FSref = $w->FileSelect(-directory => 'c:\\');
$file = $FSref->Show;
$ent->configure(-text => $file); # update the entry widget with the file
}
I get the feeling, though, that you might want to use a Listbox or a
Optionmenu. If there are only a limited number of files the user can select,
you can add entries for each and associate a subroutine to be run when the
user selects them. You don't even have to know what the files are in
advance: you could just read through whatever directory they are in and
configure the widget accordingly. You also might want to try posting to
comp.lang.perl.tk. You're probably more likely to find help getting started
with Tk there.
And finally, if you're running on Windows, you might want to consider Visual
C++ for writing GUIs. The Tk widgets are hideous to work with in Windows,
and it will take you two or three times longer (minimum!) to create a
(half-assed) Tk interface in Perl than it will to build a decent one in
Visual C++. Even if you just use it as a wrapper to your Perl script, I'd
definitely recommend avoiding Tk (unless getting a copy of Visual C++ would
come out of your own pocket, of course... : )
Matt
------------------------------
Date: 30 Jul 2003 17:30:51 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <u9lluggeo4.fsf@wcl-l.bham.ac.uk>
Steve Grazzini <grazz@pobox.com> writes:
> Tad McClellan <tadmc@augustmail.com> wrote:
> > Fred <fred.illig@lmco.com> wrote:
> >
> >> I want to call this subroutine
> >> (x) via an array element - @array = (a,b,c,x,y,z);
> >> ($outvar1, $outvar2) = &$array[3]($invar1,$invar2,$invar3);
> >
> > Use a "dispatch table".
> >
> >> How do I make a call to a subroutine where the name of the
> >> subroutine to be called is being derived from an element in
> >> an array?
> >
> > By using "symbolic references".
> >
> > But *don't do that*!
>
> Is this guilt-by-association
Yes, somewhat. See the previous thread I alluded to in another branch
of this thread.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 30 Jul 2003 10:49:58 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Irreproducible bug while using the debugger
Message-Id: <Pine.A41.4.56.0307301030090.97420@dante52.u.washington.edu>
This one stumped me until it spontaneously went away. Any explanations?
I was looking at this block of code in the debugger:
my $retval = $self->{VALUES}->{$feature};
# $retval should now be a scalar ref or undef
{
no strict 'refs';
no warnings 'uninitialized';
if ($self->{WANT} eq 'text') {
$retval = $self->{FEATURES}->text_form($feature, $$retval);
}
elsif ($self->{WANT} eq 'number') {
$retval = $$retval;
}
}
For a particular value of $feature, I found that $retval was consistently
set to '*' upon entering the less strict block, causing a warning about
deprecated use of $* on line 10. Examining $self->{VALUES} confirmed that
there was no key for the current value of $feature, so $retval should have
been undef, and there was no value for $retval before coming to this block
of code. In other words, everything was exactly as expected except for the
bizarre assignment of '*' to $retval where no value was expected.
As a partial explanation, '*' is the expected return from the text_form
method used on line 7 when the second argument is undef--but $self->{WANT}
was not set to 'text', and $retval contained the '*' before it even
reached that line.
This behavior was consistent in the debugger even after several restarts.
However, after quitting the debugge, I couldn't reproduce the bug in the
normal environment, and haven't been able to reproduce it in the bugger
since then.
Any insight?
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"
------------------------------
Date: Wed, 30 Jul 2003 16:11:25 +0100
From: "programmer" <int.consultNOCAPITALS@macmail.com>
Subject: Re: LWP::Request
Message-Id: <bg8nm4$71g$1@pheidippides.axion.bt.co.uk>
> You can type URLS of the form http://username:password@site.com/restofurl
> straight into your browser to avoid getting the popup for basic
> authentication.
That works OK for Internet Explorer, but not for Opera.
------------------------------
Date: Thu, 31 Jul 2003 06:22:20 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: LWP::Request
Message-Id: <bg99d1$m7ehp$1@ID-202028.news.uni-berlin.de>
"programmer" <int.consultNOCAPITALS@macmail.com> wrote in message
news:bg8nm4>
...
> That works OK for Internet Explorer, but not for Opera.
>
It's part of the HTTP definition. Blame Opera.
gtoomey
------------------------------
Date: 30 Jul 2003 11:16:02 -0700
From: reggie@reggieband.com (reggie)
Subject: LWP::Simple and authentication
Message-Id: <5117aba8.0307301016.74ddc0fb@posting.google.com>
hello,
when I do:
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
my $req = GET 'http://www.asaps.org/public';
$req->authorization_basic('uname', 'pwd');
my $res = $ua->request($req);
unless ($res->is_success)
{
print $res->as_string;
exit 2;
}
print $res->content;
I get:
HTTP/1.1 401 (Unauthorized) Access Denied
Date: Wed, 30 Jul 2003 18:13:58 GMT
Server: Microsoft-IIS/5.0
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
Content-Length: 24
Content-Type: text/html
Client-Date: Wed, 30 Jul 2003 18:13:08 GMT
Client-Peer: xxx.xx.x.xx.x
Client-Warning: Unsupported authentication scheme 'ntlm'
Error: Access is Denied.
I am confused.
Any suggestions?
reggie.
------------------------------
Date: Wed, 30 Jul 2003 13:36:03 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: LWP::Simple and authentication
Message-Id: <fdUVa.26$Hx3.34601@news.uswest.net>
reggie wrote:
> Client-Warning: Unsupported authentication scheme 'ntlm'
>
> Error: Access is Denied.
>
> I am confused.
> Any suggestions?
First, since you're code is correct, try to find if the solution has
already been created. Doing a Google search on "ntlm authentication
lwp", should lead you to the solution.
------------------------------
Date: Thu, 31 Jul 2003 06:18:58 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: LWP::Simple and authentication
Message-Id: <bg996n$lv4la$1@ID-202028.news.uni-berlin.de>
"reggie" <reggie@reggieband.com> wrote in message
news:5117aba8.0307301016.74ddc0fb@posting.google.com...
> hello,
>
> when I do:
>
> use LWP::Simple;
> use LWP::UserAgent;
> use HTTP::Request;
> use HTTP::Request::Common;
>
I seem to remember answering this question on ... Tuesday ...
##################################
What you probably want (as disctinct from what you asked for) is how to use
basic authentication when retrieving a page:
#!/usr/bin/perl
use LWP::Simple;
my $screen_scraper=get("http://username:password\@site.com/restofurl");
# @ has been escaped
You can type URLS of the form http://username:password@site.com/restofurl
straight into your browser to avoid getting the popup for basic
authentication.
gtoomey
------------------------------
Date: Wed, 30 Jul 2003 18:56:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl - how to compute totals via hash request
Message-Id: <3F28150A.7DE322E1@acm.org>
shree wrote:
>
> I have a tab delimited log file that contains data of system
> downtimes. It has 4 fields namely ID, type of downtime (whether
> planned or unplanned), date and duration of downtime (in secs). I'm
> asked to compute totals for each month of each type. See input data
> file provided and mocked output file.
>
> Data File (does not contain header line)
> ID Type Date DowntimeSecs
> 1 Planned 01/19/2003 5000
> 2 Unplanned 01/27/2003 900
> 3 Unplanned 01/29/2003 300
> 4 Unplanned 02/12/2003 3690
> 5 Planned 02/27/2003 1800
> ..
> ..
> 80 Planned 07/12/2003 6000
> 81 Unplanned 07/15/2003 8400
>
> Hence, the needed output file should be like
> MonthYear Planned Unplanned TotalDownTime
> Jan2003 5000 1200 6200
> Feb2003 1800 3690 5490
> ..
> ..
>
> I started with the following code
>
> my %count;
> while(<DATA>) {
> chomp;
> my ($id, $type, $date, $downtime_secs) = split (/\t/, $_);
> $count{$type} += $downtime_secs;
> }
>
> while (my ($key, $val) = each %count) {
> print "$key, $val \n";
> }
> which outputs
> Unplanned, 82000
> Planned, 90000
>
> How can I modify the above, to give my customer what they wanted. Also
> if anyone can educate me to how to extract more detailed info as shown
> below, I would greatly appreciate it. Thank you
>
> MonthYear Planned Unplanned Total NoPlanned NoUnplanned NoOfTotal
> Jan2003 5000 1200 6200 1 2 3
> Feb2003 1800 3690 5490 1 1 2
This works with the data provided:
#!/usr/bin/perl
use warnings;
use strict;
my %count;
while ( <DATA> ) {
chomp;
my ( undef, $type, $date, $secs ) = split /\t/;
( my $mon = $date ) =~ s!(\d+)/\d+/(\d+)!$2$1!;
$count{ $mon }{ sec }{ $type } += $secs;
$count{ $mon }{ cnt }{ $type }++;
}
my @mons = ( undef, qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ) );
print " --------- Seconds --------- ---------- Count ----------\n";
print "MonthYear Planned Unplanned Total Planned Unplanned Total\n";
for my $key ( sort keys %count ) {
( my $mon = $key ) =~ s/(\d{4})(\d\d)/$mons[$2]$1/;
printf "%-9s %9d %9d %9d %9d %9d %9d\n", $mon,
@{$count{ $key }{ sec }}{ 'Planned', 'Unplanned' },
$count{ $key }{ sec }{ Planned } + $count{ $key }{ sec }{ Unplanned },
@{$count{ $key }{ cnt }}{ 'Planned', 'Unplanned' },
$count{ $key }{ cnt }{ Planned } + $count{ $key }{ cnt }{ Unplanned };
}
__DATA__
1 Planned 01/19/2003 5000
2 Unplanned 01/27/2003 900
3 Unplanned 01/29/2003 300
4 Unplanned 02/12/2003 3690
5 Planned 02/27/2003 1800
80 Planned 07/12/2003 6000
81 Unplanned 07/15/2003 8400
John
--
use Perl;
program
fulfillment
------------------------------
Date: 30 Jul 2003 10:21:01 -0700
From: elegans@lycos.com (Paul)
Subject: Perl Objects
Message-Id: <d2992faa.0307300921.32765cf7@posting.google.com>
Hi all:
I was wondering if someone could help me find a *better* or more
*correct* solution to my problem.
The problem:
I have a module that parses XML data using XML::Parser. This module
is written in Object oriented fashion and defines the object in the
normal way...
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
# No args by default, args is an array ref
$self = { acode => '',
file => '',
@_
};
bless $self, $class;
return $self;
}
THe instance method parseTIGRFile is called to process the XML data
file. Within this method, XML::Parser is called and a handler is
passed to deal with XML start tags (actually there are 3 handlers, but
the question/answer is the same for all 3 handlers)....
sub parseTIGRFILE {
my $self = shift;
......
$parser = new XML::Parser(Handlers => { Start => \&handle_start,
End => \&handle_end,
Char => \&handle_char,
} );
......
}
sub handle_start {
my ($expat, $elem, @atvals)= @_;
......
}
Here is the problem... the handlers cannot not take arguments (unless
I am wrong about this... ???), so I cannot pass $self to the handler.
While the data is being parsed, I want it stored in the object's
instance variables $self->{MY_VAR}, but the handler doesn't have any
way to *see* $self.
My current solution... I have defined $self globally.
my $self;
sub new {
....
bless $self, $class;
return $self;
}
Since the parseTIGRFile method is an instance method, this
appropriately sets the instance variables (I have tested this).
However, I fear there may be a consequence to globalizing $self that I
am unaware of.
So... can anyone tell me:
1. Is my current solution acceptable?
2. Is there a better alternative?
Thanks in advance for your help... and please let me know if more
information is required.
Paul
------------------------------
Date: Wed, 30 Jul 2003 18:35:09 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl Objects
Message-Id: <rm2giv4otosjnamrb2m6elvont5bu8jtgr@4ax.com>
Paul wrote:
[problem description snipped, as it's quite long]
>So... can anyone tell me:
>1. Is my current solution acceptable?
Only if you ever use only one instance of this module at a time. That
doesn't agree with the philosophy of OO.
>2. Is there a better alternative?
I can think of a few... the safest would be to use closures for the
handlers. Let me show you how:
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
# No args by default, args is an array ref
$self = bless { acode => '',
file => '',
@_
}, $class;
$self->{handlers} = {
Start => sub {
# normal handle_start sub body. You can now access $self
...
},
End => sub {
# idem for handle_end
...
},
Char => sub {
# idem for handle_char
...
}
};
return $self;
}
and to invoke the parser, use these values in %{$self->{handlers}} for
XML::Parser.
A problem is that now you have circular references: the handler subs
refer to $self, and self refers to the handlers. You need an explicit
method to destroy these circles, by undeffing $self->{handlers} for
example, before you let got of the object.
A way to avoid that, is to use weak references, see WeakRef or
Scalar::Util on CPAN. Only, it's not clear to me how or if that is
possible...
I have an idea for weak referencing $self inside the subs, but I'm not
too sure it's actually going to work. It is that you make a copy of
$self in new(), make one of the two a weak reference, and return the
other. If the other is deleted, the subs will go too. I would hope that
might work.
Another approach: the handlers when called, get a reference to their
parser. You could put $self into a field of that object, and preferably
make it a weak reference.
I thought I knew of one more, but I seem to have forgotten it. Oh well.
--
Bart.
------------------------------
Date: Wed, 30 Jul 2003 19:25:06 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Perl training resources?
Message-Id: <u1xw7lsww.fsf@wrq.com>
"William Fields" <Bill_Fields@azb.uscourts.gov> writes:
>> Ultimately, you're only going to learn the language by playing with it,
>and
>> Perl lets you jump right into the deep end (whether that's a good thing or
>a
>> bad thing depends on how much common sense you have and how often you back
>> up your files).
>
>Yeah, I figured as much. What I'm looking for though is a way to reduce the
>trial/error cycle and learn from other's experiences in a concise manner
>(you know, best-practices and all that).
For a concise book on 'best practices', I recommend
"Effective Perl Programming"
by Joseph N. Hall with Randal L. Schwartz.
That book and 'the Cookbook' are the ones I use most.
--
-- Steve
------------------------------
Date: 30 Jul 2003 14:26:31 -0700
From: puissant00@yahoo.com (Go Perl)
Subject: perl/tk back end questions
Message-Id: <d3825316.0307301326.3195a7c5@posting.google.com>
I have a program which takes some inputs like number of inputs, and
some names of the files and then runs the simulation. Now i have
created a front end for this program using Tk. I want to connect the
front end to my program..and since i am new to GUI interfacing with my
perl program. I need help as to how i can use the text boxes, radio
buttons and list boxes to send information into my program so that i
could run from my run command on GUI.
Thanks very much for the help.
~GP~
------------------------------
Date: Wed, 30 Jul 2003 15:26:00 GMT
From: "Mark Wood-Patrick" <mlwp@pacbell.net>
Subject: printing out the values of variables in a previous stack frame using perl debugger
Message-Id: <csRVa.4471$Qd5.901@newssvr23.news.prodigy.com>
Is there any way when using the perl debugger to print out the values of
variables in a previous stack frame. This is a standard feature of debuggers
like gdb and msdev but I have read all the documents I can find and can see
no way to do this. Is this a missing feature or am I just confused.
------------------------------
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.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5293
***************************************