[19344] in Perl-Users-Digest
Perl-Users Digest, Issue: 1539 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 16 09:06:13 2001
Date: Thu, 16 Aug 2001 06:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997967110-v10-i1539@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 16 Aug 2001 Volume: 10 Number: 1539
Today's topics:
Re: "shifting" values of the @_ array?? (wade)
*UN*setting perlauth*handlers? (Felix K Sheng)
Re: checking for non-letters (Yves Orton)
Re: Comma's at end of list can break program?? (Anno Siegel)
Re: Dropping array duplicate values <samneric@tigerriverOMIT-THIS.com>
FAQ: How can I read a single character from a file? Fr <faq@denver.pm.org>
Grep Question (meadows_p)
Re: Grep Question <Tassilo.Parseval@post.rwth-aachen.de>
How replace <sda999@mail.ru>
Re: How replace (Anno Siegel)
Re: Looking for Script <dennis@noreplies.com>
Re: Looking for Script <ian.mulvihill.no.spam@computer.org>
Re: Not inserting duplicate elements into an array <skj@iobox.fi>
Re: Not inserting duplicate elements into an array (Yves Orton)
Perl OO needs the opposite of SUPER:: (John Lin)
Re: Perl OO needs the opposite of SUPER:: <ilya@martynov.org>
Re: Perl OO needs the opposite of SUPER:: <Tassilo.Parseval@post.rwth-aachen.de>
Re: perldoc is like Greek to a beginner?? (Eric Bohlman)
Re: SQL (MySQL) Windows <bart.lateur@skynet.be>
Re: SQL (MySQL) Windows <paul@net366.com>
Re: Stateful CGI - user auth <Dave.Stafford@globis.net>
Re: This is not a question ... call me slow if you like (Anno Siegel)
Re: Using a fake name on this newsgroup and in places l (Anno Siegel)
Re: Using a fake name on this newsgroup and in places l <flavell@mail.cern.ch>
Re: Would like some feedback on idea for search-engine (Laura Re)
Re: Would like some feedback on idea for search-engine (Eric Bohlman)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Aug 2001 03:28:50 -0700
From: jjchen@alumni.ice.ntnu.edu.tw (wade)
Subject: Re: "shifting" values of the @_ array??
Message-Id: <4259465b.0108160228.48d1c20d@posting.google.com>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote in message news:<MPG.15e4bf0bb5a0b96f98975f@news.edmonton.telusplanet.net>...
> Hi everyone,
>
> I have been studying and playing with the shift operator and was
> wondering...
>
> my @a = qw(Tom Mary Jack);
> method1(@a);
> method2(@a);
> method3(@a);
>
> sub method1
> {
> my $a = shift;
> print " Method - shift: $a\n";
> }
>
> sub method2
> {
> my $a = $_[0];
> print " Method - \$_[0]: $a\n";
> }
>
> sub method3
> {
> my ($a) = @_;
> print " Method - \@_: $a\n";
> }
>
Something we should know is :
. my $a = shift;
this change the array structure, and copy one element;
. my $a = $_[0];
this index one element of the array, and copy it;
. my ($a) = @_;
this copy whole array
I use method3 personally. But I think more people like to use shift.
Anyway, it depend on your job, not personally.
In common sense, shift will be the slowest(maybe not true :-).
method 2 will be the fastest(maybe not true again :=).
------------------------------
Date: 16 Aug 2001 12:11:13 GMT
From: felix@badlands.deasil.com (Felix K Sheng)
Subject: *UN*setting perlauth*handlers?
Message-Id: <slrn9nne30.udj.felix@badlands.deasil.com>
Keywords: mod_perl authenhandler authzhandler unsetting
Hello,
I think I have a strange problem, I have PerlAuth*Handler's set for
the root of my doc tree, say:
<Directory /doc/root>
PerlAuthzHandler my::module::authz_handler
PerlAuthenHandler my::module::authen_handler
..
</Directory>
Somewhere underneath that I would like to have a subtree authenticate
using the standard authuserfile and authgroupfile modules. So I have
tried any number of things including tweaking the AllowOverride in
the /doc/root Directory block. But the basic idea was:
<Directory /doc/root/subtree>
AuthUserFile /private/userfile
AuthGroupFile /private/groupfile
require group somegroup
..
</Directory>
As far as I can tell, apache is doing the directory merge properly,
first going to /doc/root and then going to .../subtree. Unfortunately,
it seems that the PerlAuth*Handler's take precedence over the AuthUserFile
directives even though they were set later. So, it is always going
to my module's handlers. I tried setting PerlAuthzHandler and
PerlAuthenHandler to nothing or empty ""'s in the .../subtree directive
but that didn't do anything.
I'm using apache 1.3.19 on a linux machine.
Can anyone shed some light on this?
Thanks.
felix
--
felix sheng ... felix@deasil.com
PGP: <http://wwwkeys.us.pgp.net:11371/pks/lookup?op=get&search=0x2CA84A01>
------------------------------
Date: 16 Aug 2001 05:24:36 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: checking for non-letters
Message-Id: <74f348f7.0108160424.6935076d@posting.google.com>
194.203.212.8 [demerphq] wrote in message news:<9lepij09ka@enews3.newsguy.com>...
Apologies about the line length in the above post.
Honest it wasnt my fault.
:-)
Yves
------------------------------
Date: 16 Aug 2001 11:21:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Comma's at end of list can break program??
Message-Id: <9lgac2$kle$1@mamenchi.zrz.TU-Berlin.DE>
According to Logan Shaw <logan@cs.utexas.edu>:
> In article <slrn9nlq47.9sn.abigail@alexandra.xs4all.nl>,
> Abigail <abigail@foad.org> wrote:
[...]
> >Also, if you do not what that comma there, you need to do extra work if
> >you would delete the last item; remove the comma on the line before.
>
> Yes, but it's just there keystrokes ('$x'), and if I forget, it's not a
> problem. :-)
If your declared style is not to have a trailing comma, it *is* a
problem.
Anno
------------------------------
Date: Thu, 16 Aug 2001 08:32:41 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Dropping array duplicate values
Message-Id: <MPG.15e586fdf73005b6989684@news.usit.net>
Paul Schnell wrote:
> Hi, The following sub takes input via a post from an
> HTML form using CGI.pm, picks up all params whose
> keys start with 'band_' and maps the values to @new,
> drops any duplicates and then saves results. It works
> fine but I was wondering if there is a way of checking
> for duplicates without the %seen and grep line.
Duplicate keys, or duplicate values ???
If values, then you would be tossing user input just because it was the same in
one input field as in another. I don't know what you're asking users on your
form, but you can use the values as hash keys if you're determined to eliminate
duplicates. "James James" can't use your form if you want the users to input
their first & last names...
But if you want to trap duplicate KEYS, then why would there even BE duplicate
keys returned from your form? That's why you assign each input a different name
- so that your script can handle the returned values correctly.
Are you using a <SELECT> that allows users to choose more than one option? If
so then you have to retrieve all of the selected values of THAT particular
input via:
my @selected_options = $cgi->param('select_box_name');
Assuming that you're not going to toss-out the values later...
Otherwise, you should be naming your form inputs (via "name=") in such a way
that there ARE no duplicates.
------------------------------
Date: Thu, 16 Aug 2001 12:17:02 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I read a single character from a file? From the keyboard?
Message-Id: <2ROe7.145$V3.191998464@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I read a single character from a file? From the keyboard?
You can use the builtin "getc()" function for most filehandles, but it
won't (easily) work on a terminal device. For STDIN, either use the
Term::ReadKey module from CPAN or use the sample code in the getc entry
in the perlfunc manpage.
If your system supports the portable operating system programming
interface (POSIX), you can use the following code, which you'll note
turns off echo processing as well.
#!/usr/bin/perl -w
use strict;
$| = 1;
for (1..4) {
my $got;
print "gimme: ";
$got = getone();
print "--> $got\n";
}
exit;
BEGIN {
use POSIX qw(:termios_h);
my ($term, $oterm, $echo, $noecho, $fd_stdin);
$fd_stdin = fileno(STDIN);
$term = POSIX::Termios->new();
$term->getattr($fd_stdin);
$oterm = $term->getlflag();
$echo = ECHO | ECHOK | ICANON;
$noecho = $oterm & ~$echo;
sub cbreak {
$term->setlflag($noecho);
$term->setcc(VTIME, 1);
$term->setattr($fd_stdin, TCSANOW);
}
sub cooked {
$term->setlflag($oterm);
$term->setcc(VTIME, 0);
$term->setattr($fd_stdin, TCSANOW);
}
sub getone {
my $key = '';
cbreak();
sysread(STDIN, $key, 1);
cooked();
return $key;
}
}
END { cooked() }
The Term::ReadKey module from CPAN may be easier to use. Recent versions
include also support for non-portable systems as well.
use Term::ReadKey;
open(TTY, "</dev/tty");
print "Gimme a char: ";
ReadMode "raw";
$key = ReadKey 0, *TTY;
ReadMode "normal";
printf "\nYou said %s, char number %03d\n",
$key, ord $key;
For legacy DOS systems, Dan Carson <dbc@tc.fluke.COM> reports the
following:
To put the PC in "raw" mode, use ioctl with some magic numbers gleaned
from msdos.c (Perl source file) and Ralf Brown's interrupt list (comes
across the net every so often):
$old_ioctl = ioctl(STDIN,0,0); # Gets device info
$old_ioctl &= 0xff;
ioctl(STDIN,1,$old_ioctl | 32); # Writes it back, setting bit 5
Then to read a single character:
sysread(STDIN,$c,1); # Read a single character
And to put the PC back to "cooked" mode:
ioctl(STDIN,1,$old_ioctl); # Sets it back to cooked mode.
So now you have $c. If "ord($c) == 0", you have a two byte code, which
means you hit a special key. Read another byte with
"sysread(STDIN,$c,1)", and that value tells you what combination it was
according to this table:
# PC 2-byte keycodes = ^@ + the following:
# HEX KEYS
# --- ----
# 0F SHF TAB
# 10-19 ALT QWERTYUIOP
# 1E-26 ALT ASDFGHJKL
# 2C-32 ALT ZXCVBNM
# 3B-44 F1-F10
# 47-49 HOME,UP,PgUp
# 4B LEFT
# 4D RIGHT
# 4F-53 END,DOWN,PgDn,Ins,Del
# 54-5D SHF F1-F10
# 5E-67 CTR F1-F10
# 68-71 ALT F1-F10
# 73-77 CTR LEFT,RIGHT,END,PgDn,HOME
# 78-83 ALT 1234567890-=
# 84 CTR PgUp
This is all trial and error I did a long time ago; I hope I'm reading
the file that worked...
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
05.26
--
This space intentionally left blank
------------------------------
Date: 16 Aug 2001 04:31:14 -0700
From: meadows_p@yahoo.com (meadows_p)
Subject: Grep Question
Message-Id: <a8af4334.0108160331.7c9d40e0@posting.google.com>
Hi,
I'm fairly new to the world of Perl and I'm currently having problems
with the following snippet of code....
sub anyFiles
{
my ($self, $files, $fh) = @_;
print $fh "In anyFiles \n";
my $bmCode = $self->{_bmCode};
print $fh "BM Code $bmCode \n";
foreach my $file (@$files) {
print $fh "file is $file\n";
}
my @foundfiles = grep($bmCode, @$files);
foreach my $foundfile (@foundfiles){
print $fh "found.... $foundfile\n";
}
return 0;
}
I'm passing a directory listing and trying to filter out the files
who's names contain the what's in $bmCode.
It displays the list of files correctly, but after my grep,
@foundfiles seems to contain exactly the same as @files.
Can anyone help me as to why my grep isn't working?
Thanks
------------------------------
Date: Thu, 16 Aug 2001 14:02:20 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Grep Question
Message-Id: <3B7BB64C.2070404@post.rwth-aachen.de>
meadows_p wrote:
[...]
offending line:
> my @foundfiles = grep($bmCode, @$files);
[...]
> It displays the list of files correctly, but after my grep,
> @foundfiles seems to contain exactly the same as @files.
>
> Can anyone help me as to why my grep isn't working?
Yes. The first argument to grep is a statement. In your case, it is a
variable containing something (thus, not undef) and therefore it is a
statement that is always true. Hence, each element of @$files is matched
against a forever true statement.
What you want is:
my @foundfiles = grep /$bmCode/, @$files;
which is equiv to
my @foundfiles = grep { $_ =~ /$bmCode/ } @$files;
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Thu, 16 Aug 2001 16:02:09 +0400
From: "Dmitry" <sda999@mail.ru>
Subject: How replace
Message-Id: <9lgcop$ckb$1@dragon.infopro.spb.su>
Source string: "abcebsasaanrart"
I want transform in "abcebsasaanraart"
i.e. replace last "a" in "aa" (count "a" - arbitrary)
How do it?
10x!
anetsoftware@mail.ru
------------------------------
Date: 16 Aug 2001 12:39:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How replace
Message-Id: <9lgeun$kle$3@mamenchi.zrz.TU-Berlin.DE>
According to Dmitry <sda999@mail.ru>:
> Source string: "abcebsasaanrart"
> I want transform in "abcebsasaanraart"
> i.e. replace last "a" in "aa" (count "a" - arbitrary)
Replace the last "a" in a string with "aa"?
s/a([^a]*)$/aa$1/;
Anno, wondering what that operation might be good for
------------------------------
Date: Thu, 16 Aug 2001 08:10:45 -0400
From: "Dennis H" <dennis@noreplies.com>
Subject: Re: Looking for Script
Message-Id: <KGOe7.42984$rV6.2110903@e420r-atl2.usenetserver.com>
Uhhhh... why?
"T Mesbah" <tmesbah@hotmail.com> wrote in message
news:6e9d9699.0108151340.4493cafd@posting.google.com...
> Hi,
>
> 1) I have two Cisco router routerA and routerB.
> 2) In routerA I have static route "ip route X.X.X.X Y.Y.Y.Y Z.Z.Z.Z"
> to access routerB.
>
> I am looking for script that ping routerB each 5 minutes and if
> routerB is down then the script need to telnet to routerA and remove
> these static route.
>
> Many Thanks
------------------------------
Date: Thu, 16 Aug 2001 13:41:20 +0100
From: "Ian M" <ian.mulvihill.no.spam@computer.org>
Subject: Re: Looking for Script
Message-Id: <3b7bc173$0$227$cc9e4d1f@news.dial.pipex.com>
"Dennis H" <dennis@noreplies.com> wrote in message
news:KGOe7.42984$rV6.2110903@e420r-atl2.usenetserver.com...
>
>
> Uhhhh... why?
>
>
> "T Mesbah" <tmesbah@hotmail.com> wrote in message
> news:6e9d9699.0108151340.4493cafd@posting.google.com...
> > Hi,
> >
> > 1) I have two Cisco router routerA and routerB.
> > 2) In routerA I have static route "ip route X.X.X.X Y.Y.Y.Y Z.Z.Z.Z"
> > to access routerB.
> >
> > I am looking for script that ping routerB each 5 minutes and if
> > routerB is down then the script need to telnet to routerA and remove
> > these static route.
> >
> > Many Thanks
>
>
That's what routing protocols are for. Is this too easy and efficient?
Either you have a more complicated and unsual reason to do it this way, or
misunderstand the (preferable) options. Do you want clarify what you're
trying to solve, and we could make some suggestions?
Cheers,
Ian
--
ian.mulvihill@nospam.computer.org
------------------------------
Date: Thu, 16 Aug 2001 15:11:11 +0300
From: Sami Jarvinen <skj@iobox.fi>
Subject: Re: Not inserting duplicate elements into an array
Message-Id: <MPG.15e5215db369eea7989680@news.yhteys.mtv3.fi>
Yves Orton wrote
> "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
> news:<3B7A80F1.4F6FD00C@stomp.stomp.tokyo>...
[ snip ]
> > Why would I deliberately break my code?
> You dont have to 'deliberately break' your code. It was broken from
> the beginning.
[ snip ]
Please, *please* stop feeding the troll. No matter how exquisite bits of
wisdom you give him (her, it, whatever), the result will always stink.
Maybe someone ought to write a Troll-Avoidance-HOWTO, "Giant lizard
droppings, how to avoid them", or something like that.
*g*
------------------------------
Date: 16 Aug 2001 05:18:40 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Not inserting duplicate elements into an array
Message-Id: <74f348f7.0108160418.37828a6f@posting.google.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> shrilly whined in message
news:<3B7AF568.8B406ED5@stomp.stomp.tokyo>...
> Yves Orton blathered, drooled and told lies:
Lies? Yes, respond to criticism with invective. It indicates your
maturity, your confidence in yourself and your integritiy. Ie LOW.
>
> > Godzilla! wrote:
> > > Jasper McCrea aka Yves Orton aka The CLPM Troll aka Ad Nauseam trolled:
Lizard, why do you assume that we are all the same person all the
time. Do you suffer from multiple personality disorder combined with
a serious transference problem?
> > > > Godzilla! wrote
> There is no doubt about your enjoying being the
> loving mouthpiece for geekster boys around here.
You mean I love destroying your code? Correct. You are the type of
person that abuses the newbies, gives them crappy solutions and then
pretends that you are the next thing to Elvis. While normally I like
pissing people like you off, its especially personal as you have in
earlier posts stated that a solution of mine did not work, WITHOUT
being able to prove it. So What I have done is decided to analyse the
shit out of your posts so that A)No newbie takes your bug ridden
advice B)Eventually you actually start being nice, or preferably C) go
away.
I was even thinking that perhaps we should set up a web site of your
measly little scripts so that the newbies can go and learn how NOT to
program.
Now on to a finer analysis of your duplicate removal algorthim. Pay
attention, you just _might_ learn something.
So first off, what order will your code run in? The easiest way to
work this out is to assume that @Array_New contains ONLY unique single
letters and @Array_Old is empty.
Such as
my @Array_New=qw(A B C D E F G);
my @Array_Old=();
Now when we run the code snippet the lizard provided
my $count=0;
for (@Array_New)
{
my $list_old = "@Array_Old"; # added my to comply with strict()
print $count++.":'$list_old'\n";# added print to see whats going on
if (index ($list_old, $_) == -1)
{ push (@Array_Old, $_); }
}
We get
0:''
1:'A'
2:'A B'
3:'A B C'
4:'A B C D'
5:'A B C D E'
6:'A B C D E F'
Now, from the code it is clear that
A) Each iteration of the loop we recreate $list_old
B) Each iteration of the loop we search $list_old for some string
This means that in simple terms we will have (for n elements)
0+1+2+3+..+n
operations just building $list_old. Which if we all remember our math
classes is one of newtons formulas, which he solved to be:
($n+1)*($n/2)
Which if you do your sums can be shown to grow rather fast.
$n ($n+1)*($n/2)
1 1
10 55
100 5050
1000 500500
10000 50005000
100000 5000050000
1000000 500000500000
Now if we were to use this algorithm on the full set of chars we would
need
32896 operations, but wait its worse! In fact using the method above
we actually have joined the list by a space, so each iteration the
string would be
2*$n-1 chars long. So in fact the above numbers are low by around
half.
Since we are searching the string for each character using index and
each char is unique we are going to have to move through the entire
$list_old for each iteration. This means that essentially $n must be
multiplied by two. So for the case of 256 character elements we will
have to do something like
2102275 operations (ignoring bits like the operations required for the
if and the push) which is obtained from the following formula
(((2*$n+1)*2)+1)*(((2*$n+1)*2)/2)
^^Elems
^^^^^^Length of $list_old
^^^^^^^^^^^^ Ops to build and search $list_old
So the end result is that we will need at least 2.1 million operations
to use the above algorithm for a list of 256 unique character
elements! Considering that it is unlikely that anyone would want to
do this on a set of characters, but would rather be dealing with
strings then these numbers get a whole lot bigger.
When this order O(($n+1)*($n/2)) [Q? Can this be reduced?? Not sure]
is considered the order for a hash O(1) seems, well, to be prefered.
So now the question is can this algorithm be improved?
Of course it can. First we can make a minor change and all of a
sudden its running time is cut in half!
my $count=0;
my $list_old = "@Array_Old"; # added my to comply with strict()
for (@Array_New)
{
print $count++.":'$list_old'\n";# added print to see whats going on
if (index ($list_old, $_) == -1)
{
push (@Array_Old, $_);
$list_old.=$" if length($list_old);
$list_old.=$_;
}
}
So thats one improvement, but can we do anything else?
Hmm, well we can make changes that actually make the algorithm work.
I say this reffering to the substring problem. Imagine that the only
element in @Array_Old is "ABCDEF" if we then try to add the array
above we see that none of the single char elements will be added to
the array! Obviously this is a problem!
[It should be noted that were we to need a method that would prevent a
stirng being added to the array if it IS a substring of something
already in the array then this strategy might be nice.]
So if we can say that there is at least one character that will
_never_ occur in any element of the array we can at least solve this
problem. Lets assume that this character is "\0". Now we would have
to use code like this:
local $"="\0";
my $count=0;
my $list_old = "\0@Array_Old\0"; # added my to comply with strict()
for (@Array_New)
{
print $count++.":'$list_old'\n";# added print to see whats going on
if (index ($list_old, "\0$_\0") == -1)
{
push (@Array_Old, $_);
$list_old.="$_\0";
}
}
Unfortunately, this algorithm is still O(($n+1)*($n/2)), AND it
restricts what characters can be used in the elements of the array.
These factors suggest that using a hash which operates in O(1) and has
no restrictions is probably the superior method.
Yves
------------------------------
Date: 16 Aug 2001 03:06:04 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108160206.f368c4b@posting.google.com>
Before I post, I already knew it's hard to make myself understood because
I can't master English well (at least not good enough). It often happens.
OK, let me ask some questions (assuming A inherits Base).
When you are designing the Base class, how can you make sure calling
A->init;
will also call Base::init? Use $self->SUPER::init, right?
package Base;
sub init { print "Yes, Base::init is called first.\n" }
package A;
our @ISA = 'Base';
sub init {
my $self = shift;
$self->SUPER::init;
print "Then, A::init is called.\n";
}
package main;
A->init;
__END__
Yes, Base::init is called first.
Then, A::init is called.
But the code is in package A, not in package Base.
When I am designing Base, I want the code to be in package Base.
The only way for current Perl to do it is like
package Base;
sub Base::init {
my $self = shift;
print "Yes, Base::init is called first.\n";
$self->on_init;
}
package A;
our @ISA = 'Base';
sub on_init { print "Then, A::init is called.\n" }
package main;
A->init;
__END__
Yes, Base::init is called first.
Then, A::init is called.
You have to rename A::init, otherwise (if you overwrite with A::init)
calling A->init will not reach Base::init at all.
I can only accept renaming as a work-around because I don't want the same
attribute/method in the inheritance tree to have different names.
sub Creature::init;
sub Animal::init__creature_calls_animal;
sub Dog::init__animal_calls_dog;
Dog->init; # actually calls Creature::init
If 'virtual' is available
sub Creature::init : virtual;
sub Animal::init : virtual;
sub Dog::init : virtual;
Dog->init;
by my definition, Dog->init will try to call Animal::init first,
which will try to call Creature::init first. Thus, the sequence will be
Creature::init;
Animal::init;
Dog::init;
And the call-linking code (like SUPER::) is written in the base class,
not in the inherited class.
All in all,
SUPER:: provides call-linking from bottom to up
@ISA provides method searching from bottom to up
VIRTUAL:: provides call-linking from top to bottom
: virtual provides method searching from top to bottom
The latter two are considered (by me) to be important too
because the process of designing polymorphism is "top to bottom".
Thank you.
John Lin
------------------------------
Date: 16 Aug 2001 14:17:02 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <87bslgpaw1.fsf@abra.ru>
JL> Before I post, I already knew it's hard to make myself understood because
JL> I can't master English well (at least not good enough). It often happens.
JL> OK, let me ask some questions (assuming A inherits Base).
JL> When you are designing the Base class, how can you make sure calling
A-> init;
JL> will also call Base::init? Use $self->SUPER::init, right?
JL> package Base;
JL> sub init { print "Yes, Base::init is called first.\n" }
JL> package A;
JL> our @ISA = 'Base';
JL> sub init {
JL> my $self = shift;
JL> $self->SUPER::init;
JL> print "Then, A::init is called.\n";
JL> }
JL> package main;
A-> init;
JL> __END__
JL> Yes, Base::init is called first.
JL> Then, A::init is called.
JL> But the code is in package A, not in package Base.
JL> When I am designing Base, I want the code to be in package Base.
I don't understand what you want to achive. If you have some common
initialization code you put it in base class in some method. If you
have class specific initialization code you override method from base
class with your specific initialization code. Since you want to be
nice and don't forget to call common initialization code you also use
SUPER:: to call method from base class in method of your
subclass. What is the problem with such approach? It common aproach
for any (at least I think so) OO language.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Thu, 16 Aug 2001 13:14:47 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <3B7BAB27.6040508@post.rwth-aachen.de>
John Lin wrote:
> Before I post, I already knew it's hard to make myself understood because
> I can't master English well (at least not good enough). It often happens.
>
> OK, let me ask some questions (assuming A inherits Base).
>
> When you are designing the Base class, how can you make sure calling
>
> A->init;
>
> will also call Base::init? Use $self->SUPER::init, right?
Prefixing init with SUPER:: is necessary if package A overrides the
init-method of Base. If A does not have an init-method, then Base::init
is automatically called. This also works with multiple base classes:
@ISA = qw(Base1 Base2);
Calling A->init will call Base1::init if A does not override init and
will call Base2::init if A does not override init and Base1::init does
not exist. So, the super classes are searched in the order they are to
be found in @ISA.
So, if A does have an init-method as well and you explicitely want to
call init of the supercall, you indeed have to write A->SUPER::init.
However, I wonder whether this would make sense and whether you
shouldn't consider your object hierarchy once more.
> You have to rename A::init, otherwise (if you overwrite with A::init)
^^^^^^^^^
Speaking in terms of object-orientedness, 'overwrite' does not exist. It
is 'override' in fact.
> All in all,
>
> SUPER:: provides call-linking from bottom to up
> @ISA provides method searching from bottom to up
Ok, these exist as you know.
> VIRTUAL:: provides call-linking from top to bottom
> : virtual provides method searching from top to bottom
These two are just not necessary. Read again my other reply to you and
see the code of Base::new which illustrates how you can call the method
of the sub-class without these two above constructs. You just don't need
them if you use the two-argument version of bless().
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 16 Aug 2001 10:54:19 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <9lg8or$ofh$1@bob.news.rcn.net>
Yves Orton <demerphq@hotmail.com> wrote:
> abigail@foad.org (Abigail) wrote in message news:<slrn9nlrlb.9sn.abigail@alexandra.xs4all.nl>...
>> Also, Aho, Hopcroft and Ullman claim that almost every computer language
>> is context free, so it would be interesting to see you prove them wrong.
> Id be interested to see the cite on this one. It contradicts my
> recollection of the red dragon.
> The annoying thing is that when I left for work today I briefly
> considered taking it with me... But ive got the hardcover version and
> I didnt want the weight when I rode my bicycle to work....
pp. 179-181.
Note, BTW, that Perl regexen with backreferences can specify languages
that are not only not regular, but not context-free. /([ab]*)c\1/ is a
classic illustration. Yet not all context-free languages can be specified
by them (without some new experimental features, they can't match an
arbitrary number of balanced parentheses, that being about the simplest
example of a context-free language that isn't regular).
------------------------------
Date: Thu, 16 Aug 2001 11:00:43 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: SQL (MySQL) Windows
Message-Id: <h59nntoelus7o9nv6t65rfb24ood8q3qqg@4ax.com>
Paul Fortescue wrote:
>I think I'm being a donkey. I have installed MySQL on Win2K, and downloaded
>the modules DBI and DBD which I have put into the /perl/lib directory
You must be referring to DBD::mysql, because DBD isn't a module.
>When I try to run a .pl script using use DBI I get 'Compilation failed in
>require at ... '
>
>I assume that the require is in the DBI.pm module, and it is looking for DBD
Well, you snipped the part that says exactly where it fails, and why.
But anyway, "use" is a superset of "require". Maybe that is a clue.
DBI will only attempt to load the DBD driver when you try to connect to
a database using some driver. Is your connect string alright?
>Am I being stupid? Does anyone know the MINIMUM installation for MySQL?
I think you need the MySQL client software. I haven't use MySQL on
Win32, so I'm not too damn sure.
Check out the links at <http://dbi.symbolstone.org>. It should point to
a FAQ on installing and using DBI with MySQL on Win32. I can't check
right now, because there seems to be a problem with the server.
Check out the docs that come with DBD::mysql too. They give a lot of
info on installation problems.
You can check the website of MySQL for documentation. There's a mailing
list archive. There's a mailing list, if the archive comes up blank. ;-)
<http://www.mysql.com/documentation/>
And finally, for help on DBI, check out the dbi-users mailing list.
There too there's an archive.
<http://lists.perl.org/showlist.cgi?name=dbi-users>
--
Bart.
------------------------------
Date: Thu, 16 Aug 2001 13:11:30 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: SQL (MySQL) Windows
Message-Id: <997963920.28999.0.nnrp-01.d4f094e4@news.demon.co.uk>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:h59nntoelus7o9nv6t65rfb24ood8q3qqg@4ax.com...
> Paul Fortescue wrote:
>
> >I think I'm being a donkey. I have installed MySQL on Win2K, and
downloaded
> >the modules DBI and DBD which I have put into the /perl/lib directory
>
> You must be referring to DBD::mysql, because DBD isn't a module.
>
> >When I try to run a .pl script using use DBI I get 'Compilation failed in
> >require at ... '
> >
> >I assume that the require is in the DBI.pm module, and it is looking for
DBD
>
> Well, you snipped the part that says exactly where it fails, and why.
>
> But anyway, "use" is a superset of "require". Maybe that is a clue.
>
> DBI will only attempt to load the DBD driver when you try to connect to
> a database using some driver. Is your connect string alright?
>
> >Am I being stupid? Does anyone know the MINIMUM installation for MySQL?
>
> I think you need the MySQL client software. I haven't use MySQL on
> Win32, so I'm not too damn sure.
>
> Check out the links at <http://dbi.symbolstone.org>. It should point to
> a FAQ on installing and using DBI with MySQL on Win32. I can't check
> right now, because there seems to be a problem with the server.
>
> Check out the docs that come with DBD::mysql too. They give a lot of
> info on installation problems.
>
> You can check the website of MySQL for documentation. There's a mailing
> list archive. There's a mailing list, if the archive comes up blank. ;-)
>
> <http://www.mysql.com/documentation/>
>
> And finally, for help on DBI, check out the dbi-users mailing list.
> There too there's an archive.
>
> <http://lists.perl.org/showlist.cgi?name=dbi-users>
>
> --
> Bart.
I have installed DBI.pm in the /lib, and have used "use DBI::mysql" as you
suggest. Therefore I have installed mysql.pm in /lib/DBI.
It contains # -*- perl -*-
package Mysql;
use 5.004;
use strict;
require Carp;
require DynaLoader;
require Exporter;
require DBI;
require Mysql::Statement;
require DBD::mysql;
and now I get Compilation failed in require at C:/Perl/lib/DBI/mySQL.pm line
11. whgich appears to be the line "require DBI".
I have DBI.pm in the /lib and also in /lib/DBI just in case I really don't
understand!
So I am still stuck, but appreciate your comments! I think I have everything
I need except some experience of how Perl looks for modules :)
------------------------------
Date: Thu, 16 Aug 2001 11:51:02 GMT
From: "Dave Stafford" <Dave.Stafford@globis.net>
Subject: Re: Stateful CGI - user auth
Message-Id: <GsOe7.432083$XL1.7186630@nlnews00.chello.com>
"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
>
> > So if you use this you should use a secure session
>
> If your security audit calls for that level of safety then yes, you
> should; but use of https has other significant consequences, so it
> should not merely be adopted by rote.
Sure, and there are other ways such as Digest-based authentication which has
less processing and network overhead.
It is horses for courses, and I agree entirely that you should perform a
risk assessment to decide which method is best for you.
> This is basic authentication we're talking about here. There _is_ no
> "login": it's sloppy talk to call it that, and it routinely leads to
> misunderstandings and additional insecurities.
Er..yes there is. I'd argue that it was your intrepretation that was
sloppy:-)
I use login in the generally accepted sense, i.e. the process that the user
must complete when he/she accesses a protected resource. E.g. type in a
userid and password, select a certificate whatever.
The *authentication* process must occur every connection to the web server,
but from the user perspective that is not always a login process.
To prevent the user having to re-enter his/her userid/password for every
visit to the web site, the userid/password is replaced with a session ID
that cannot be changed (or in the case of basic authentication the
userid/password is cached in the HTTP headers).
Caching of credentials is used at all levels. HTTP basic authentication is
fundamentally no different to TCP using sequence numbers to identify each
packet exchange in e.g. a telnet session. And the fact that telnet sessions
can be stolen shows how this simple "authentication" mechanism breaks down.
That said, I agree that people should be aware that anauthentication process
must occur for every session to the web server to properly protect
resources.
Dave
------------------------------
Date: 16 Aug 2001 10:12:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <9lg6am$hbg$1@mamenchi.zrz.TU-Berlin.DE>
According to Benjamin Goldberg <goldbb2@earthlink.net>:
[...]
> And using just uuencoding works even better, and doesn't require an
^^^^^^^^^^^^^^^^^^
> external module:
^^^^^^^^^^^^^^^^
Major winnitude!
Anno
------------------------------
Date: 16 Aug 2001 11:35:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Using a fake name on this newsgroup and in places like perlmonks??
Message-Id: <9lgb6m$kle$2@mamenchi.zrz.TU-Berlin.DE>
According to Buck Turgidson <noway@nohow.com>:
> When I run for the Senate 20 years from now, I don't want my enemies
> dredging up any unseemly ranting and ravings that I've posted.
We'll just out you as a top-poster.
Anno
------------------------------
Date: Thu, 16 Aug 2001 13:59:30 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Using a fake name on this newsgroup and in places like perlmonks??
Message-Id: <Pine.LNX.4.30.0108161358360.4091-100000@lxplus023.cern.ch>
On Aug 16, Anno Siegel declaimed to the assembled multitude:
> According to Buck Turgidson <noway@nohow.com>:
> > When I run for the Senate 20 years from now, I don't want my enemies
> > dredging up any unseemly ranting and ravings that I've posted.
>
> We'll just out you as a top-poster.
And full-quoter too, egad.
--
"Always remember you're unique, just like everyone else."
- I'm-no-Lady Polgara, quoting Anonymous
------------------------------
Date: 16 Aug 2001 03:41:14 -0700
From: laura.re@iconmedialab.co.uk (Laura Re)
Subject: Re: Would like some feedback on idea for search-engine
Message-Id: <d85eaf5a.0108160241.3af80026@posting.google.com>
Hi Wouter -
You can use a DBM file as your database. The data in the file is
basically a hashtable (or associative array in perlspeak), and it's
created and searched by a specific set of APIs. I just did a search at
cpan.org and turned up this module:
http://theoryx5.uwinnipeg.ca/CPAN/data/DBM-DBass/DBass.html
Also look at the Gnu web site at their description of their GDBM
module. It's for C, not Perl, but the idea is the same.
-Laura
"W.A.J. Vijvers" <wvijvers@SAYNOTOSPAMscience.uva.nl> wrote in message news:<3B73C7E8.FD197564@SAYNOTOSPAMscience.uva.nl>...
> Hi fellow perlers,
> I'm writing a CGI application that manages an online archiving system.
> I'm now starting to implement a search-engine for the archive and I
> would like some feedback on the idea I have for it. Maybe you're
> thinking I should use a RDBMS or a fancy module, but I would like to
> impose as little as possible on the systems that this will run on (I
> want to sell it as a self-contained package), so I want to go with a
> textfile-based database. All the info about the documents in the archive
> is contained in its filename (format:
> Title_of_doc.yyyymmdd.author.kenmerk.ext (dunno a translation of
> kenmerk)). I want the users to be able to search for either title, date
> or kenmerk within a certain date-range. For the search I would like to
> create an index of the following form:
>
> ===============
> search_title.db
> ===============
> 20010809|Title of doc
> :Title of doc|Name
> Surname|09-08-2001|kenmerk|ext|category/sub-cat|maybe.full.filename.here
> (...repeat for every document...)
>
> ===============
> search_author.db
> ===============
> 20010809|Name Surname
> :Title of doc|Name
> Surname|09-08-2001|kenmerk|ext|category/sub-cat|maybe.full.filename.here
>
> and a similar file for "kenmerk" and three more for hidden documents
> (non-public ones, to be accesed with password). This would allow me to
> run through the file pretty quickly (skipping all the lines that start
> with ":" unless the previous line matched). Another opion would be to
> only have "Title_of_doc" on the first line and then check the date-range
> in the second line if the title matched. The fact that I have to build 3
> different databases doesn't bother me that much.
>
> What do you guys think of this idea? Can it be easier? Should I use
> DB_File and a different format instead? I should note that it has to run
> on both Windows and UNIX. I think that the maximum number of files in
> the archive will be about 1000 (probably along the lines of 400-500).
> I'm also open to completely different solutions.
>
> Thanks a lot, regards,
> Wouter
------------------------------
Date: 16 Aug 2001 11:16:16 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Would like some feedback on idea for search-engine
Message-Id: <9lga20$t8n$1@bob.news.rcn.net>
Laura Re <laura.re@iconmedialab.co.uk> wrote:
> You can use a DBM file as your database. The data in the file is
> basically a hashtable (or associative array in perlspeak), and it's
Actually, it's just a "hash" in modern (i.e. since 1994) perlspeak. If it
had been up to me, I'd have called it a "lookup" since I think the name
should reflect what it does rather than how it's implemented; it could
have been implemented as, say, a btree rather than a hash table. But the
terminology has stuck.
------------------------------
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 1539
***************************************