[23013] in Perl-Users-Digest
Perl-Users Digest, Issue: 5233 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 17 14:10:49 2003
Date: Thu, 17 Jul 2003 11:10:17 -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 Thu, 17 Jul 2003 Volume: 10 Number: 5233
Today's topics:
md5sum of umounted cd-rom (warning: 'orrible perl code (Robert Lynch)
Re: Newbie OO question (Salvador Fandino)
Perl hangs when returning lvalue closure from another l <julian@mehnle.net>
Re: Read index.dat file? <cat@no-spam.com>
Re: Read index.dat file? (brice)
Re: Read index.dat file? <usenet@dwall.fastmail.fm>
Return 403 from mod_perl program <ppagee@yahoo.com>
Re: Return 403 from mod_perl program <noreply@gunnar.cc>
Re: Return 403 from mod_perl program <ppagee@yahoo.com>
Re: system("clear"); vs. system("cls"); <cat@no-spam.com>
Re: Test for file existence <jurgenex@hotmail.com>
Re: using fifo (jr)
Re: Using Perl / MYSQL for a large database application <cwilbur@mithril.chromatico.net>
Re: Where are the perl folks? (Randal L. Schwartz)
Re: Why is 'last' not allowed here (Ronald Fischer)
Re: Why is 'last' not allowed here <abigail@abigail.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jul 2003 10:30:18 -0700
From: rmlynch@pacbell.net (Robert Lynch)
Subject: md5sum of umounted cd-rom (warning: 'orrible perl code ahead)
Message-Id: <1ffe5f4f.0307170930.19fdc250@posting.google.com>
How do you compute the md5sum of a cdrom you have burned? Googling
seems to reveal this to be a "difficult" problem. The complaint is
something like: "I burned the CD, but now the md5sum is different than
the one posted on the download site!"
It appears to me that the problem is related to file block size,
padding, etc.
One can find the size of a cd-rom in linux using the command "isosize"
(from util-linux package). Then you can (hack, hack, chop, mangle...)
compute it as follows:
===
# $Id: md5.pl,v 1.2 2003/07/17 17:15:11 user Exp user $
# reads md5sum from unmounted CD-ROM in drive
# run as perl -w md5.pl
use Digest::MD5;
# CD-ROM device file on my system.
$file = "/dev/scd0";
# Install/adjust path to isosize depending on distro
my $size = `/usr/bin/isosize $file`;
#print "Size of $file: $size\n";
# Read $size bytes into a variable
# Perl Cookbook, p. 276
# TODO - read chunks, compute md5sum
# so as not to bog down system.
open FH, $file or die "Couldn't open $file: $!\n";
my $read = sysread(FH, $data, $size, 0);
close FH;
# Lifted from Digest::MD5 man page
my $md5 = Digest::MD5->new;
$md5->add($data);
$digest = $md5->hexdigest;
print "$digest - $file\n";
===
I'm sure you whizzes will take one whiff of this (while holding your
noses) and then immediately come up with something neater and perlish.
But in the meantime: "There's More Than One Way To Do It."
Bob L.
------------------------------
Date: 17 Jul 2003 09:17:39 -0700
From: sfandino@yahoo.com (Salvador Fandino)
Subject: Re: Newbie OO question
Message-Id: <35ce19d9.0307170817.3718462b@posting.google.com>
Hi Ed,
"Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote in message news:<SItRa.362198$fC.2630720@news.easynews.com>...
> > perldoc perltoot
> >
> > it's all you need... that and maybe damian's book!:
> >
> > http://www.manning.com/Conway/
>
> Thanks, I have read the perltoot page a few times, but it doesn't seem to
> cover what happens if you want to inherit from an object that has, say, a
> scalar as the underlying object storage, but I need somewhere to store some
> extra object variables.
>
> I suspect that there is something clever possible involving closures, but
> since I'm not quite ready for that yet, I was just wondering if there was a
> standard way out of this...
I know three different ways to do what you want:
1 - use a "has-a" relation instead of a "is-a" one.
Compress::PPMd::Compressor and Compress::PPMd::Decompressor have very
few methods so you only need to write a few proxy methods to call
them.
2 - use a hash private to your package indexed by the Compress::PPMd
objects (untested):
package MyPkg;
use Compress::PPMd;
our @ISA=qw(Compress::PPMd::Compressor);
my %data; # here goes your data
sub new {
my $class=shift;
my $this=$class->SUPER::new(@_);
$data{$this}={ foo => 'bar' }
}
# data(...) stores and retrieves your class object properties
# $obj->data('foo') retrieves property 'foo'
# $obj->data('bar', 'doz') sets property 'bar' as 'doz'
sub data {
my $this=shift;
my $key=shift;
if (@_) {
$data{$this}{$key}=$_[0];
}
else {
return $data{$this}{$key}
}
}
sub DESTROY {
my $this=shift;
delete $data{$this}
eval { $this->SUPER::DESTROY(@_) }
}
3 - tell me why you need to extend the package and maybe I will add
that functionality to Compress::PPMd ;-)
Bye,
- Salva.
------------------------------
Date: Thu, 17 Jul 2003 17:13:26 +0200
From: "Julian Mehnle" <julian@mehnle.net>
Subject: Perl hangs when returning lvalue closure from another lvalue closure
Message-Id: <bf6eeq$bbtl3$1@ID-65075.news.uni-berlin.de>
Hi all,
I'm having a serious problem that using lvalue closures in a Perl class
module causes Perl to hang. I have wasted days on researching the problem,
but could not find a solution. I think it might be a bug in Perl; I'm using
5.8.0, but can reproduce the behavior on 5.6.1 as well.
I failed to trim the scenario down to a pure sample program to demonstrate
the bug, so I have to present you the whole thing (it's not that big,
though):
http://files.mehnle.net/tmp/perl-lvalue-closures/ -- or: --
http://files.mehnle.net/tmp/perl-lvalue-closures.tar.gz
To execute the scenario, call "test.pl".
The core is DBIx::Class, which is meant to transparently implement object
persistency. USM::Class and USM::User are exemplary classes that are
derived from DBIx::Class like this:
DBIx::Class <-- USM::Class <-- USM::User
Every class shall be able to have inheritable, overrideable class (not
instance) fields, so I used the same mechanism Class::Data::Inheritable
uses: For every class field, create a closure with its own field storage
variable. If the closure is called from a derived class to modify the field
value, it creates a new closure in the namespace of the derived class with
its own field storage variable. It's supposed to work like this:
DBIx::Class->foo('nil');
# DBIx::Class->foo eq 'nil'
# USM::Class->foo eq 'nil'
USM::Class->foo('zippo');
# DBIx::Class->foo eq 'nil'
# USM::Class->foo eq 'zippo'
Now I wanted to be clever and make these closures into lvalue subs to allow
code like
DBIx::Class->foo = 'nil';
USM::Class->foo = 'zippo';
See the class field accessor closure created by the _create_class_field sub
in DBIx/Class.pm:
253: my $accessor = sub :lvalue {
254: my $want_class = shift();
255: $want_class->_class_only();
256:
257: no strict 'refs';
258:
259: # Is field to be modified, and doesn't sub-class already have its
# own accessor?
260: if (@_ and ($want_class ne $class)) {
261: # Create an accessor for sub-class, and return its $value as
# an lvalue:
262: # $want_class->_create_class_field($field)->($want_class, @_);
263: my $acc = $want_class->_create_class_field($field);
264: $acc->($want_class, @_);
265: # $value; # DEBUG, this doesn't belong here!
266: }
267: else {
268: # We are a closure, so _create_class_field()'s $value is used
269: # for the field's storage:
270: $value = shift() if @_;
271: # Return $value as an lvalue:
272: $value;
273: }
274: };
To make a long story short, Perl hangs in in line 264, when calling the
newly created accessor closure. If I insert a dummy lvalue after that call,
like in line 265, then Perl does NOT hang, and returns from both the old and
the newly created accessor successfully, although of course the wrong lvalue
is then returned from the old accessor.
Perl seems to hang in some kind of internal endless loop (100% CPU load),
`strace` shows no more syscalls during the hang. Perl only terminates if I
press <CTRL+C> eventually.
I also tried debugging the thing in the Perl debugger, see "debug.log" for a
debugger session log. Interestingly, manually performing the
`$acc->($want_class, @_)` call (via the `x` debugger command when the
debugger is in line 264) works. Though, as soon as the debugger does the
call from the module's code, it hangs again.
So all things considered, I guess the problem has to do with how Perl
returns lvalues from lvalue subs. Any ideas?
--
Julian Mehnle.
------------------------------
Date: Thu, 17 Jul 2003 20:37:08 +1000
From: Cat <cat@no-spam.com>
Subject: Re: Read index.dat file?
Message-Id: <3F167C54.F39F95CE@no-spam.com>
brice wrote:
>
> I was wondering if it was possible to read the contents of the
> 'index.dat' files on the Windows platform using Perl. If so, could
> someone please include links to resources for docs or modules that
> would accomplish this?
>
What is or where is this index.dat file? Is it binary or text? What
do you want to do after opening it?
------------------------------
Date: 17 Jul 2003 05:01:02 -0700
From: bricemason@hotmail.com (brice)
Subject: Re: Read index.dat file?
Message-Id: <50404b7a.0307170401.78c67ec4@posting.google.com>
Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3F15D7DD.20002@rochester.rr.com>...
>
> Sure:
>
> perldoc -f open
> perldoc -f read
I believe this is a binary file used as an Internet Explorer database
on history of sites visited and cookies. This method will not work. I
was hoping to find out what possible Win32 module would be out there
to accomplish this.
------------------------------
Date: Thu, 17 Jul 2003 15:51:13 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Read index.dat file?
Message-Id: <Xns93BB7894D20E6dkwwashere@216.168.3.30>
brice <bricemason@hotmail.com> wrote:
[reading index.dat files]
> Bob Walton <bwalton@rochester.rr.com> wrote in message
> news:<3F15D7DD.20002@rochester.rr.com>...
>>
>> Sure:
>>
>> perldoc -f open
>> perldoc -f read
>
>
> I believe this is a binary file used as an Internet Explorer
> database on history of sites visited and cookies. This method will
> not work. I was hoping to find out what possible Win32 module
> would be out there to accomplish this.
It'll work, you just need to know the format of the index.dat file.
But that has nothing to do with Perl. Ask Microsoft about that file.
:-)
I'd also recommend
perldoc -f binmode
------------------------------
Date: Thu, 17 Jul 2003 12:33:09 +0200
From: Mike Mimic <ppagee@yahoo.com>
Subject: Return 403 from mod_perl program
Message-Id: <hXuRa.353$2B6.56918@news.siol.net>
Hi!
I have a mod_perl program and I would like that the client
viewing it would get a 403 response if some criteria are
matched. Otherwise it should output normal page (program's
normal output).
How can I do this?
Mike
------------------------------
Date: Thu, 17 Jul 2003 14:40:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Return 403 from mod_perl program
Message-Id: <bf65ih$bfo56$1@ID-184292.news.uni-berlin.de>
Mike Mimic wrote:
> I have a mod_perl program and I would like that the client
> viewing it would get a 403 response if some criteria are
> matched. Otherwise it should output normal page (program's
> normal output).
>
> How can I do this?
By printing it (as a header):
print "Status: 403 Forbidden\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 17 Jul 2003 19:58:19 +0200
From: Mike Mimic <ppagee@yahoo.com>
Subject: Re: Return 403 from mod_perl program
Message-Id: <CsBRa.366$2B6.57638@news.siol.net>
Hi!
> By printing it (as a header):
>
> print "Status: 403 Forbidden\n";
Thanks.
Mike
------------------------------
Date: Thu, 17 Jul 2003 21:09:40 +1000
From: Cat <cat@no-spam.com>
Subject: Re: system("clear"); vs. system("cls");
Message-Id: <3F1683F4.BA0F655A@no-spam.com>
Buteo Lagopus wrote:
>
> Using ActiveState Perl 5.8.0, system("clear"); raises an error on Win2k
> Pro: "clear is not recognized as an internal or external command, operable
> program or batch file." but that's what perldoc says to use.
>
> I tried system("cls"); and it worked correctly.
>
> Is perldoc in error or is this an OS port issue? I'd hope this won't cause
> cross-platform problems.
Try this....
#!/bin/perl
use strict;
use warnings;
use diagnostics;
my ($screen_clear, $file_remove, $file_copy, $file_move);
if ($^O =~ /MSWin32/) {
#
# Set up Windows variables
#
$screen_clear = "cls";
$file_remove = "del";
$file_copy = "copy";
$file_move = "move";
}
else {
#
# Set up UNIX variables
#
$screen_clear = "clear";
$file_remove = "rm";
$file_copy = "cp";
$file_move = "rm";
}
system("$screen_clear");
------------------------------
Date: Thu, 17 Jul 2003 13:12:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Test for file existence
Message-Id: <IgxRa.18833$kI5.8508@nwrddc02.gnilink.net>
Brian Berneker wrote:
> File existence test is simple
>
> if (-e "filename") { whatever }
Hmmm, sure, yes. Just like documented in perldoc -f -X.
Is there anything special about it that surprises you or that you would like
to discuss?
jue
------------------------------
Date: 17 Jul 2003 09:50:36 -0700
From: scw_00@yahoo.com (jr)
Subject: Re: using fifo
Message-Id: <b574c5ab.0307170850.43e7b6cd@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<bf3e4p$akcan$1@ID-184292.news.uni-berlin.de>...
> jr wrote:
> > Thanks. i found out the solution.
>
> We are all very happy for you. Would you mind sharing it?
Sure, this is my pleasure and i support all open source products. Yes,
i am using DBI, isql won't work based on my understanding, hope i am
wrong. i list the most important section here, the rest of them should
be easy as long as you know the DBI ( sybase ) on my case. Send e-mail
to me if you need help.
start the program as a daemon when server is up. when the monitoring
script send the error messages to DBA,
then DBA
1. echo "select * from sysprocesses" >> /opt/....in_file ( you can
pipe any cmds you want )
2. check output file that you open for output in your script.
3. echo "kill spid" ( kill the user connection you want )
4. check output file.
5. echo "select count(*) from sysproceses" >> /opt/...in_file ( check
total connections )
i haven't done the automation on this scripts yet, will do it when it
more mature.
------------------------------------------------------------------------
## check fifo input file, if there is info, then exec the statement
#
my $fifo = '/opt/sybase/FIFO_DIR/in_file';
unless (-p $fifo) { #unless the file is not a pipe
if (-e _) {
die "$0: we don't want to overwrite the file\n";
} else {
require POSIX;
POSIX::mkfifo($fifo, 0666) or die "Can't create our pipe";
warn "$0: created $fifo as a named pipe for cmd input\n";
}
}
while (1) {
open(FIFO,"< $fifo") or die "Can't open $fifo for reading";
while (<FIFO>) {
print "cmd---$_\n";
$sth=$dbh->prepare($_); $sql_rc1 = $sth->execute;
then you loop the $_ to print to a file.
}
close(FIFO);
}
------------------------------
Date: Thu, 17 Jul 2003 16:42:40 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Using Perl / MYSQL for a large database application
Message-Id: <87ptk99knd.fsf@mithril.chromatico.net>
Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> 2 million records is not much. MySQL can easily deal with that.
>
> There is, however, no reason to go for other commercial software [1]
> if you have a task that MySQL doesn't perform well for certain tasks.
> PostgreSQL is a very decent RDBMS, and for almost all tasks equal
> to, or better than MySQL.
The quantity of records is not nearly as important as the quantity,
frequency, and complexity of queries -- if you have many complex
queries, MySQL will fall down hard.
MySQL's principal advantages are that it is fast and that it doesn't
require any great brains to get running. It's principal disadvantages
are a lack of features (subselects, transactions -- though they're
reportedly either available if you use a particular table type or
coming Real Soon Now) and poor performance under heavy load.
If you expect to want a richer dialect of SQL than MySQL offers, or
better performance under load, and you're committed to an open source
solution, you'll probably want PostgreSQL.
Charlton
------------------------------
Date: Thu, 17 Jul 2003 16:05:35 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: "Eric J. Roode" <sdn@comcast.net>
Subject: Re: Where are the perl folks?
Message-Id: <06fbace54c940358c08241c2ddc62456@free.teranews.com>
>>>>> "Eric" == Eric J Roode <sdn@comcast.net> writes:
Eric> The comp.lang.perl.announce moderators don't seem to be around anywhere.
If you didn't get my autoreply, then I never saw the message. I
usually either post or reject within an hour or two of seeing it
(sending back an email for either), but I sometimes don't see it for a
day or two.
If you use a spamproofed email, I generally just toss the message. I
won't post anything to CLPA without a valid return email, and I don't
spend any effort at all to decode the email to say so.
Although my logging is not as good as it could be, I don't recall
anything from you recently.
Eric> I posted a message there a couple weeks ago; it hasn't shown
Eric> up. I sent a followup email asking about status, but it has so
Eric> far been unanswered.
If you sent email to me, and I didn't see it, then my spam filters
probably swallowed your email. I use SpamAssassin augmented with
conservative relay block lists. Perhaps your host is being blocked.
Eric> No new modules / namespaces have been accepted by pause.perl.org in a
Eric> couple weeks. Someone posted a question asking about this to
Eric> modules@perl.org, and it has gone unanswered.
Eric> I tried to join perl5-porters a week or two ago. I sent a blank email to
Eric> the address specified at dev.perl.org, and nothing has happened -- no
Eric> confirmations, no rejections, and no mailing list messages.
Eric> What is going on?
Wait... there's a theme here. A *lot* of your emails are being
dropped. Sounds like you either have a bad outgoing mail connection,
or your mail relay has been spam-targeted. Maybe you should look
into that.
print "Just another Perl hacker," # and CLPA moderator
--
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: 17 Jul 2003 03:27:05 -0700
From: ronaldf@eml.cc (Ronald Fischer)
Subject: Re: Why is 'last' not allowed here
Message-Id: <219750c.0307170227.2cff1f13@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<bf353t$8e6$1@nets3.rz.RWTH-Aachen.DE>...
> That's because the blocks of 'if', 'unless' and 'do' (missed one?)
> aren't treated as a block that is subject to 'last' or 'next'.
The strange thing is that the manpages explain that 'do' can't be
used, but they tell nothing about if. Just the contrary: They say
that, WRT blocks, 'if' behaves like a loop ('while', 'for').
I *see* that Perl does not treat the if-"block" as a block, but
this contradicts the documentation, isn't it? So either the implementation
or the docs are wrong in this respect.
Ronald
------------------------------
Date: 17 Jul 2003 10:38:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Why is 'last' not allowed here
Message-Id: <slrnbhcv5t.53v.abigail@alexandra.abigail.nl>
Ronald Fischer (ronaldf@eml.cc) wrote on MMMDCVII September MCMXCIII in
<URL:news:219750c.0307170227.2cff1f13@posting.google.com>:
%% "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<bf353t$8e6$1@nets3.rz.RWTH-Aachen.DE>...
%% > That's because the blocks of 'if', 'unless' and 'do' (missed one?)
%% > aren't treated as a block that is subject to 'last' or 'next'.
%%
%% The strange thing is that the manpages explain that 'do' can't be
%% used, but they tell nothing about if. Just the contrary: They say
%% that, WRT blocks, 'if' behaves like a loop ('while', 'for').
Which manual page is that?
Abigail
--
perl -Mstrict='}); print "Just another Perl Hacker"; ({' -le1
------------------------------
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 5233
***************************************