[11436] in Perl-Users-Digest
Perl-Users Digest, Issue: 5036 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 2 18:07:28 1999
Date: Tue, 2 Mar 99 15:00:33 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 2 Mar 1999 Volume: 8 Number: 5036
Today's topics:
A smiple question <tangd@ctcdist.com>
Re: can't locate loadable object for module? <monroy@cig.mot.com>
Re: CGI.pm question (Martien Verbruggen)
Re: CGI.pm <gellyfish@btinternet.com>
Re: Determine web directory size (Dimitri Ostapenko)
Re: Determine web directory size (Dimitri Ostapenko)
Re: Finding the word after a word <arnej@fc.hp.com>
Re: Finding the word after a word (Sam Holden)
Re: Finding the word after a word jwmauney@yahoo.com
Re: Help - regex to extract two fields in "uptime" (Charles DeRykus)
Re: How do I get Perl Modules to run in my webspace? dturley@pobox.com
Re: How do I get Perl Modules to run in my webspace? <gellyfish@btinternet.com>
Re: How to parse telephone numbers from string (I R A Aggie)
HTML to MSWORD, PDF, POSTSCRIPT <kcchan@csis.hku.hk>
Re: logically impaired <gellyfish@btinternet.com>
Re: logically impaired (Martien Verbruggen)
MAIL file attachments in Perl Script <Webmaster@qax.org>
Re: MAIL file attachments in Perl Script (Abigail)
Re: method overriden! <ekkis@arix.com>
Re: method overriden! (Abigail)
Re: method overriden! <ekkis@arix.com>
Re: method overriden! (Martien Verbruggen)
Re: method overriden! <ekkis@arix.com>
Re: next in a continue block restarts continue block, b (Chris Sherman)
Re: next in a continue block restarts continue block, b <cassell@mail.cor.epa.gov>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 2 Mar 1999 16:53:41 -0600
From: "Dong Tang" <tangd@ctcdist.com>
Subject: A smiple question
Message-Id: <a2_C2.421$66.20853@ptah.visi.com>
How do I detect if a string has any non-numeric character in it by using
regular expression, but code below doesn't work.
$foo = "3w43242";
if ($foo =~ /![0-9]/)
{
print "$foo has non-numeric charater.\n"
}
I am a Perl newbie, so you know the answer, could you email at
tangd@ctcdist.com
Thanx
Don Tang
------------------------------
Date: Tue, 02 Mar 1999 14:50:08 -0600
From: Leo Monroy <monroy@cig.mot.com>
Subject: Re: can't locate loadable object for module?
Message-Id: <36DC4F00.7EBE93E6@cig.mot.com>
It appears that you don't have the LDAPapi module installed on your system check
out CPAN site to download the module and for instructions on how to install it.
dubing@lisco.com wrote:
> Hello there,
>
> My perl script need to:
>
> use Net::LDAPapi;
>
> So I added:
>
> BEGIN {
> push(@INC, '/net/info/pub/sun4/lib/perl5-/site_perl');
> }
>
> at the beginning of the script. LDAPapi.pm is located in the subdir of the
> above dir.
>
> However when I run this script, I still got the following error:
>
> Can't locate loadable object for module Net::LDAPapi in @INC (@INC
> contains: /public/lib/perl5/5.00501/sun4-solaris /public/lib/perl5/5.00501
> /public/lib/perl5/site_perl/5.005/sun4-solaris
> /public/lib/perl5/site_perl/5.005 . /net/info/pub/sun4/lib/perl5-/site_perl)
> at ./sample.pl line 8 BEGIN failed--compilation aborted at ./sample.pl line
> 8.
>
> Note: line 8 is "use Net::LDAPapi"
>
> What's wrong? Can anybody help me out of this problem? Because I do not
> come to this group quite often, please send me your help at
> bing-du@cis-gw.tamu.edu.
>
> Thanks in advance for your help.
>
> Bing
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 02 Mar 1999 22:30:18 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: CGI.pm question
Message-Id: <_DZC2.76$hc3.684@nswpull.telstra.net>
In article <36DB8914.762E89AE@nus.edu.sg>,
Jeremy <scijr@nus.edu.sg> writes:
> i'm using CGI.pm module. In a perl script, i tried to display a text1 +
> button1 and when button1 presses will show text2 + button2 . But when
> button2 pressed....a text which is suppossedly to appear did not. Can
> anyone help ?
It's line 16 of your code.
Maybe you should show it to us.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: 2 Mar 1999 21:31:53 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: CGI.pm
Message-Id: <7bhlc9$1kv$1@gellyfish.btinternet.com>
On Tue, 2 Mar 1999 18:40:35 +0100 Dixie Flatline wrote:
> Hi!
>
> From where can I obtain the CGI.pm modole for PERL 5.004?
>
I thought that it came with the 5.004.04 distribution. However if you
really havent got it then you can get it from CPAN at:
<http://www.perl.com/CPAN/authors/id/LDS/CGI.pm-2.49.tar.gz>
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Tue, 02 Mar 1999 22:16:57 GMT
From: euclid@fantom.com (Dimitri Ostapenko)
Subject: Re: Determine web directory size
Message-Id: <trZC2.64$xJ4.254@198.235.216.4>
In article <ebohlmanF7y6wn.KvE@netcom.com>,
Eric Bohlman <ebohlman@netcom.com> writes:
> Maria Ostapenko <dimitrio@sympatico.ca> wrote:
>: This is a multi-part message in MIME format.
>
> Please configure your newsreader to post single-part messages in plain
> text format.
>
>: Try this: (excuse my wordiness, I'm only learning..)
>
>
>: #!D:/perl/bin/perl -w
>: my ($d, @f, $tsz);
>
>: $d = "D:/perl/bin";
>: opendir (DIR, $d) || die "Could not open dir $!";
>: @f = readdir DIR;
>
>: $tsz=0;
>: for (@f) {
>: $tsz += -s;
>
Right you are! I only noticed it after I posted the message. Well, guess you have to chdir to $d then.
> Bzzt! The filenames in $_ have no pathnames prepended, so -s is looking
> for the sizes of files in the current directory, which may bear no
> relation to $d.
>
>: }
>: print $tsz;
>: closedir DIR;
------------------------------
Date: Tue, 02 Mar 1999 22:31:25 GMT
From: euclid@fantom.com (Dimitri Ostapenko)
Subject: Re: Determine web directory size
Message-Id: <1FZC2.66$xJ4.254@198.235.216.4>
In article <MPG.1144ffab770f5c1e9896bd@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) writes:
> [Posted and a courtesy copy mailed.]
>
> In article <36DB4913.D7A4FAF@sympatico.ca>, on Mon, 01 Mar 1999 21:12:35
> -0500 dimitrio@sympatico.ca says...
>> Try this: (excuse my wordiness, I'm only learning..)
>
> Welcome to the group. One of the first things you should learn is to
> test your code before posting it -- even if you don't think you need to.
Thanks. I did. It works. Not everywhere though. Big deal, chdir $d.
I am trying to help my namesake here, ok?
>
>> #!D:/perl/bin/perl -w
>> my ($d, @f, $tsz);
>>
>> $d = "D:/perl/bin";
>> opendir (DIR, $d) || die "Could not open dir $!";
>> @f = readdir DIR;
>>
>> $tsz=0;
>> for (@f) {
>> $tsz += -s;
>> }
>> print $tsz;
>> closedir DIR;
>
> This code works iff the directory you are reading happens to be the
> current directory. This is because the readdir function returns only
> the names, which are relative to the current directory. To work in
> general, you must supply an absolute filename:
>
> $tsz += -s "$d/$_";
Umm, I like this better, actually, more portable than chdir, that's for sure.
>
>> Dimitri Ostapenko,
>> Not another perl hacker (yet)
>>
>> Dmitry Diskin wrote:
>>
>> > Hi,
>> >
>> > Is there any simple solution for count the total size of files in
>> > particular directory of web server?
>> >
>> > Dmitry.
>
> It is more appropriate to put the question you are answering ahead of
> your answer, not after it.
>
Ok.
> And it is totally inappropriate to include this garbage in your
> response:
>
>> begin:vcard
>> n:Ostapenko;Dimitri
> ...
>
> Use a signature of not more than four lines, preceded by the standard
> cut-string "-- \n".
>
Yes, Sir. Promise not to do it again, Sir. (It's not me, it's netscape (or should I say Mozilla?))
_END_
------------------------------
Date: Tue, 02 Mar 1999 14:04:30 -0700
From: Arne Jamtgaard <arnej@fc.hp.com>
Subject: Re: Finding the word after a word
Message-Id: <36DC525E.726D@fc.hp.com>
Abigail wrote:
> kalikste@uiuc.edu (kalikste@uiuc.edu) wrote on MMVIII
> September MCMXCIII in <URL:news:7bf4j7$ap3$1@nnrp1.dejanews.com>:
> ## Quick question for a regular expression-
> ##
> ## What is the most elegant way to extract the word after a specific
> ## word in a string (words seperated by one space)? For example, if
> ## the string is "The quick brown fox jumps over the lazy dog", given
> ## "brown", I want to return "fox". In my situation, each word will
> ## only appear once in the string. I appreciate all your input.
> sub find_next_word {
> my ($word, $string) = @_;
> for (my ($i, @words) = (0, split / / => $string); $i < @words; ) {
> last if $words [$i ++] eq $word;
> }
> return $words [$i];
> }
> Abigail
I tried this, and couldn't get it to work unless I moved the
"my" defining $i and @words to before the for-loop. I think
by putting them in the for-loop declaration, they're out of
scope by the time you get to the return statement.
Or am I missing something?
Arne
------------------------------
Date: 2 Mar 1999 22:29:26 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Finding the word after a word
Message-Id: <slrn7dopi6.svu.sholden@pgrad.cs.usyd.edu.au>
On Tue, 02 Mar 1999 14:04:30 -0700, Arne Jamtgaard <arnej@fc.hp.com> wrote:
>
>I tried this, and couldn't get it to work unless I moved the
>"my" defining $i and @words to before the for-loop. I think
>by putting them in the for-loop declaration, they're out of
>scope by the time you get to the return statement.
>
>Or am I missing something?
Your missing a newer version of perl...
--
Sam
Another result of the tyranny of Pascal is that beginners don't use
function pointers.
--Rob Pike
------------------------------
Date: Tue, 02 Mar 1999 22:21:23 GMT
From: jwmauney@yahoo.com
Subject: Re: Finding the word after a word
Message-Id: <7bho8q$jnq$1@nnrp1.dejanews.com>
In article <0k8gb7.l4q.ln@magna.metronet.com>,
tadmc@metronet.com (Tad McClellan) wrote:
> kalikste@uiuc.edu wrote:
>
> : What is the most elegant way to extract the word after a specific word in a
> : string (words seperated by one space)?
>
> ----------------------
> #!/usr/bin/perl -w
> use strict;
>
> my $string = 'The quick brown fox jumps over the lazy dog';
>
> my $word = 'brown';
>
> print "'$1'\n" if $string =~ /\b$word (\S+)/;
^^
Tad, may I suggest adding \b to eliminate false positives for
$word='he'|'own'|'ox'.
> ----------------------
>
> --
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 2 Mar 1999 20:59:39 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <F7zJnF.q@news.boeing.com>
In article <MPG.1144efb6889b07329896bc@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>[Posted and a courtesy copy mailed.]
>...
>You stop matching against $uptime and start matching against $_ on the
>second line.
>The regexes aren't correct, partly because each one has become a local
>match in a set of local matches, rather than one great big match across
>the entire string. (More on this later.)
>Also, I'd be very concerned about breaking out too soon if one of those
>matches had a zero value. How about commas and parentheses? The 'and'
>tests on the right should be replaced by simple sequence commas or
>(gasp) semicolons.
Good grief... you're correct. (I was in the grip of creating a
cute quip about semicolons :).
>
>Having said all that, I benchmarked a corrected version against both of
>the other ways previously posted, with these conclusions:
>
>1. Although 'qw( time uptime ... )' looks like a constant list that
>could be computed at compile-time, it is actually a run-time evaluation
>(split ' ', 'time uptime ...') that creates a list which is the same
>each time through the loop. Is there a potential optimization here?
>Lesson: Don't use 'qw' in loops or inside of benchmarked code!
>
>2. My hash-slice approach wasn't faster than doing the explicit
>assignments. Lesson: Intuition fails yet again.
>
>3. Your version with the multiple local regexes is almost twice as fast
>as the single big regex. This probably has to do with the amount of
>backtracking performed, which depends on how the big regex is written.
>Lesson: Doing several individual matches sequentially *may* be
>significantly faster than doing a global match.
>
Thanks for a very interesting look at this - the speed
difference was a total suprise. I just hoping to make the
subexpression matchs and the corresponding hash assignments
easy to follow.
--
Charles DeRykus
------------------------------
Date: Tue, 02 Mar 1999 22:01:28 GMT
From: dturley@pobox.com
Subject: Re: How do I get Perl Modules to run in my webspace?
Message-Id: <7bhn3j$imc$1@nnrp1.dejanews.com>
In article <nXAznHAANB32EwtX@dragroup.com>,
Graham Stow <graham@dragroup.com> wrote:
> use Getopt::Long;
> use English;
> use DB_File;
>
> I have done this and my ISP tells me to upload these modules to my CGI-
> BIN Directory,
Whyt is your ISP telling to install modules that are part of the standard
perl library? This makes me think that your ISP is using an old version of
Perl. When you do perl -v what do you find out?
I am amazed at how many ISP think the current Perl is 5.001! I know of one
major provider of web hosting space that has 5.003 as default, saying any
later versions are "experimental." --
____________________________________
David Turley
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 2 Mar 1999 21:28:10 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: How do I get Perl Modules to run in my webspace?
Message-Id: <7bhl5a$1j6$1@gellyfish.btinternet.com>
On Tue, 2 Mar 1999 16:35:12 +0000 Graham Stow wrote:
> I am trying to create and access a DBM file in my webspace, and the
> script I am using (from a Perl 5 How-To) says I should use the DBM
> module by useing the following lines in my script..
>
> use Getopt::Long;
> use English;
> use DB_File;
>
> I have done this and my ISP tells me to upload these modules to my CGI-
> BIN Directory, and this I have done (with the exeption of Getopt - I
> didn't have Getopt.pm but I did have Long.pm so I uploaded this instead
> and call it with the line 'use Long;' in my script).
>
> However, the script that creates and writes to the DBM file keeps
> crashing the moment it encounters the line 'use Long;' or if I comment
> this line then it crashes at 'use English;', or if I comment them both
> then it crashes at 'use DB_File'.
>
You cant just install DB_File like that. It has a binary XS component that
requires to be installed properly.
I would recommend that you try and get your ISP to install the module for
you.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 2 Mar 1999 21:32:28 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: How to parse telephone numbers from string
Message-Id: <slrn7domc6.jnf.fl_aggie@enso.coaps.fsu.edu>
On Tue, 02 Mar 1999 17:16:32 +0300, Sergey Ivanov <sergey@callcenter.ru> wrote:
+ I did it this way:
Ah, but who's telephone numbers?
+ $_ = $string_to_parse;
+ my $tel;
+ for $tel (/(\d\d\d\-\d\d\-\d\d)/gc) {
+ ## $tel processing
+ }
+
+ Can anybbody give me a better advise?
I don't know what Russian phone numbers are like, and have at best
vague experience with non-USA numbers...
James
------------------------------
Date: Wed, 3 Mar 1999 02:46:44 +0800
From: Rollo Chan Ka Chun <kcchan@csis.hku.hk>
Subject: HTML to MSWORD, PDF, POSTSCRIPT
Message-Id: <Pine.GSO.4.03.9903030245230.14197-100000@virtue.csis.hku.hk>
Is there any method or module which can convert a HTML file to MSWORD or
PDF or POSTSCRTIPT file???...thanks for your attention and help.
Regards,
Rollo
------------------------------
Date: 2 Mar 1999 21:55:24 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: logically impaired
Message-Id: <7bhmoc$1l6$1@gellyfish.btinternet.com>
On Tue, 02 Mar 1999 20:09:46 +0100 Staffan Liljas wrote:
> Jonathan Feinberg wrote:
>> Staffan Liljas <staffan@ngb.se> writes:
>> > > open FILE or die "$FILE $!";
>> > I don't think this opens the file.
>> Why don't you think so?
>
> Because I'm stupid, and I'm currently working my way towards the record
> for supplying the most incorrect information to clp.misc in a day.
>
Nah I think that I won that one Saturday about a year ago when I'd had too
many bottles of Budvar ;-}
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Tue, 02 Mar 1999 22:26:53 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: logically impaired
Message-Id: <NAZC2.74$hc3.684@nswpull.telstra.net>
In article <36DBE627.35D5F234@ngb.se>,
Staffan Liljas <staffan@ngb.se> writes:
> Oliver Moffat wrote:
>> if ($hits == 0){ # if no hits, we look harder
>> foreach $FILE (@_){
>> open FILE or die "$FILE $!";
>
> I don't think this opens the file.
It does. It uses the special bit of open that states:
# perldoc -f open
=item open FILEHANDLE,EXPR
=item open FILEHANDLE
Opens the file whose filename is given by EXPR, and associates it with
FILEHANDLE. If FILEHANDLE is an expression, its value is used as the
name of the real filehandle wanted. If EXPR is omitted, the scalar
variable of the same name as the FILEHANDLE contains the filename.
(Note that lexical variables--those declared with C<my()>--will not work
for this purpose; so if you're using C<my()>, specify EXPR in your call
to open.)
Whether it's a good idea to use this or not is another discussion :)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 02 Mar 1999 21:29:54 +0000
From: Colin Drew <Webmaster@qax.org>
Subject: MAIL file attachments in Perl Script
Message-Id: <36DC5851.B2B223B2@qax.org>
Help required with Perl and Email Attachements.
I would like to email a FILE attachment such as a ZIP or TXT or even JPG
file directly from my server and obviously want it to arrive still as an
attachment, not part of the email body ?
I don't want to run the mailprog and read the content of the file in
question and output it into the email message, I need it as an
attachment and to retain its original format . Similar to the way a
Browser is able to attach files and keep them separate. But I need this
to run on the www server unattended !
I am not a novice to Perl, and I have written many Scripts from scratch,
but this problem has completely eluded me. Any help will be appreciated
!
If any one can give me a snippet of code showing the perl syntax
(example preferably) for adding multiple NON text files to an email as
attachments I will be forever grateful. I have tried unsuccessfully
(for days) to find some examples / instructions on the internet.
Some background info to be aware of :
I am writing scripts (some are CGI's) under win98 (uhhhgg) using
"ActivePerl" as my perl interpreter, the PC is NOT set up as a server. I
am using the Perl interpreter to just check for syntax etc. of the
scripts and test the file read/write functions of the scripts. This
saves many hours each month (time is money) of modem connection fees.
These scripts are then ftpd to my WWW space once this testing is
complete. On my www server I do NOT have access to telnet (they don't
allow it, and I have asked and been refused) and this causes big
problems because I am unable to access the Perl manuals (At least I cant
think of a way too see them without telnet !) Yet another problem is
getting hold of the perl manuals in html that is NOT in a UNIX tar
archive (cant read/decompress these). I have bought 2 Perl books to
help me with Perl, but these are not terribly forthcoming with this
particular problem.
--
From Colin Drew,
You can Email
mailto:Colin@qax.org or mailto:WebMaster@qax.org
Why not visit my WebSite :- http://www.qax.org/
---------------------------------------------------------------------
Any Syntax or Spelling Errors are nothing to do with me,
They must be Transmission Errors !
---------------------------------------------------------------------
------------------------------
Date: 2 Mar 1999 22:02:41 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: MAIL file attachments in Perl Script
Message-Id: <7bhn61$t6c$1@client2.news.psi.net>
Colin Drew (Webmaster@qax.org) wrote on MMIX September MCMXCIII in
<URL:news:36DC1453.58C1F85D@qax.org>:
~~ Help please !
~~ For perl only please.
~~
~~ I would like to email a FILE attachement such as a ZIP or TXT or even
~~ JPG file directly from my server and obviously want it to arrive still
~~ as an attachement, not part of the email body ?
I don't think the header is the appropriate place....
Mail only cares about headers and a body. "Attachements" is something
MIMEish.
Did you try the various MIME::* and Mail::* modules?
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
Date: Tue, 2 Mar 1999 14:02:27 -0800
From: "Ekkis" <ekkis@arix.com>
Subject: Re: method overriden!
Message-Id: <kdZC2.6350$8N5.70111@typhoon-sf.pbi.net>
>you are a bit confused.
and a bit transparent, apparently :)
>since you have an init() function in both classes, but
> the object is blessed into the derived class
I'm being a bit obtuse, which object?
>the object is going to look in the derived class first even if the
>object is used in the base class.
maybe I just didn't build it right or maybe I don't understand how it's
supposed to work. In my mind there's a difference between a virtual
function and a callback: reference to a virtual function is always local
i.e. in $self-init() $self resolves to c1 while within c1 scope and to c2
while in c2 scope. A callback on the other hand allows a base class to call
a derived class's functions. What I have here is a callback, what I want is
a virtual function.
>step through your code again keeping this in mind and you'll see
>how it happens :)
ok, here's how it looks when we unfold it, starting with the first call:
c2->new();
my $proto = shift; # contains c2
my $class = ref($proto) || $proto; # ref() fails, uses $proto
my $self = $class->SUPER::new(); # call to base constructor
my $proto = shift; # contains c1
my $class = ref($proto) || $proto; # ref() fails, uses c1
my $self = {}; # ref to empty hash
bless($self, $class); # make obj in c1
$self->init(@_); # c1::init()
return $self; # blessed ref 2 empty hash
bless($self, $class); # re-bless into c2
$self->init(@_); # c2::init()
return $self; #
------------------------------
Date: 2 Mar 1999 22:06:31 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: method overriden!
Message-Id: <7bhnd7$t6c$2@client2.news.psi.net>
Ekkis (ekkis@arix.com) wrote on MMIX September MCMXCIII in
<URL:news:rZMC2.5866$8N5.68922@typhoon-sf.pbi.net>:
() It seems that when I inherit from a class, if I create a method with the
() same name as one of the base class's methods, the base class loses access to
() it's own method! Consider the following (see 3 files below): a call to
() c2->new() generates a call to the base class constructor c1->new() which
() calls its helper sub init(). That call ($self->init()) should resolve to
() c1->init(), but doesn't!! instead c2->init() gets called. Thus when
That's the point of objects! The object is of class 'c2', so for
finding methods, it will first look in 'c2'. It finds init in the
class 'c2', so c2::init is called, *not* c1::init.
() c1->new() returns and c2->new() continues and calls ITS own init(),
() c2->init() is called for a second time. Can someone explain to me why? and
() what can be done to protect the base class's access to it's own methods?
Don't call it in the OO way. Call it the regular way:
c1::init ($self, ...);
Abigail
--
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))
------------------------------
Date: Tue, 2 Mar 1999 14:09:28 -0800
From: "Ekkis" <ekkis@arix.com>
Subject: Re: method overriden!
Message-Id: <QjZC2.6401$8N5.70260@typhoon-sf.pbi.net>
>$self->init(@_) calls the init method for the object $self; since $self
>is of class c2, this is the subroutine c2::init.
but, doesn't $self resolve differently depending on the scope of usage?
after all, why should references in the base class actually be obscured by
derived classes?
>You probably want to write
>
> $self->c1::init(@_);
>
>to ensure that the init method for class c1 is called.
do you mean to say that I have to hard-code references to myself if there's
ever the possibility that some derived class some day will use a name the
same as mine? or otherwise I lose access to my own methods? when I write
$self->init()
in the new() constructor for my class I mean to init stuff for my class, not
for some derived class! The derived class shouldn't have to know to call
the base class's init() or any other particular internal functionality of my
class otherwise good God!
I'm not building it right, but I can't figure out quite how.
TIA - e
------------------------------
Date: Tue, 02 Mar 1999 22:34:17 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: method overriden!
Message-Id: <JHZC2.78$hc3.684@nswpull.telstra.net>
In article <rZMC2.5866$8N5.68922@typhoon-sf.pbi.net>,
"Ekkis" <ekkis@arix.com> writes:
> It seems that when I inherit from a class, if I create a method with the
> same name as one of the base class's methods, the base class loses access to
> it's own method! Consider the following (see 3 files below): a call to
[snip]
What you are seeing is perfectly normal, and indeed exactly how it
should be. When a method is called against an object, it will find the
first method in the inheritance tree that fits, and it starts at the
class level the object was blessed into. If you call a method against
a class, it will start looking at the class you explicitly mention.
This is the whole point of inheritance.
I think you probably don't understand fully how OO is supposed to
work. Have you read the perltoot documentation? It explains all of
this quite well.
# perldoc perltoot
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 2 Mar 1999 14:41:21 -0800
From: "Ekkis" <ekkis@arix.com>
Subject: Re: method overriden!
Message-Id: <KNZC2.6463$8N5.70114@typhoon-sf.pbi.net>
>That's the point of objects! The object is of class 'c2', so for
>finding methods, it will first look in 'c2'. It finds init in the
>class 'c2', so c2::init is called, *not* c1::init.
when you say "the object" you really mean the thing returned by c2->new() so
I can understand that if I say:
$o = c2->new();
$o->init();
the call will resolve to c2::init(). But why should calls in a base class
resolve to code defined in derived classes? that is callback behaviour, not
virtual functions.
- e
------------------------------
Date: Tue, 2 Mar 1999 21:46:23 GMT
From: sherman@unx.sas.com (Chris Sherman)
Subject: Re: next in a continue block restarts continue block, but...
Message-Id: <F7zLtB.CFA@unx.sas.com>
In <linberg-0203991236400001@ltl1.literacy.upenn.edu> linberg@literacy.upenn.edu (Steve Linberg) writes:
>In article <F7z7DM.Fno@unx.sas.com>, sherman@unx.sas.com (Chris Sherman) wrote:
>> How do I do something like a next, but _not_ have it restart
>> in the continue block since I'm already in it?
> I'm not clear what you're trying to accomplish.
What I want to accomplish is to do a next inside a continue block
that will go all the way back up to the top and do the while
condition, and if true, do the while block.
What it does instead is just restart the continue block _without_
re-evaluating the while condition.
If I could change the definition of next slightly, I would make it
not automatically jump to the continue block if it is _already_ in
the continue block.
So I'm looking for easy syntax that does do a "next, but bypass the
continue block".
> If you want to exit the loop, use last.
Don't want to exit the loop.
> If you want to execute based on a condition, use a while
> construction and set the condition inside the loop. If you
> want to continue inside the block only if certain criteria are
> met, and otherwise restart the loop, try "next unless
> (condition)".
Here is when I think you don't understand my problem. The "next"
inside a continue block refuses to re-evaluate the while
conditional. It just goes back a couple of lines and restarts
the continue block. I can't really break out of the continue
block in any nice way without blowing away the entire while loop
(ie, last).
>It's rarely a good idea to set up infinite loops without terminating
>conditions, in my experience, unless that's really what you intend.
I agree completely. I'm finding a way to prevent this using the
limitations placed on perl's command set (ie, next).
> I almost always find it better and safer to explicitly state
> the exit conditions in the loop declaration, even if it's just
> a flag reflecting the state of something happening inside.
Setting a flag wouldn't matter. The while is never re-evaluated.
> Makes it clearer to the reader/maintainer/you-two-weeks-later
> when the loop ends.
Yes... I can mess up the logic with a lot of useless flag-waving
(pun intended), but I was hoping to not have to do that...
Next, redo, and last can make really knarly logic statements so
much easier to read and write.
Thanx for the response!!
--
____/ / / __ / _ _/ ____/
/ / / / / / / Chris Sherman
/ ___ / _/ / /
_____/ __/ __/ __/ _\ _____/ _____/ sherman@unx.sas.com
------------------------------
Date: Tue, 02 Mar 1999 14:23:26 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: next in a continue block restarts continue block, but...
Message-Id: <36DC64DE.428B2307@mail.cor.epa.gov>
Chris Sherman wrote:
>
> In <linberg-0203991236400001@ltl1.literacy.upenn.edu> linberg@literacy.upenn.edu (Steve Linberg) writes:
>
> >In article <F7z7DM.Fno@unx.sas.com>, sherman@unx.sas.com (Chris Sherman) wrote:
>
> >> How do I do something like a next, but _not_ have it restart
> >> in the continue block since I'm already in it?
>
> > I'm not clear what you're trying to accomplish.
>
> What I want to accomplish is to do a next inside a continue block
> that will go all the way back up to the top and do the while
> condition, and if true, do the while block.
>
> What it does instead is just restart the continue block _without_
> re-evaluating the while condition.
>
> If I could change the definition of next slightly, I would make it
> not automatically jump to the continue block if it is _already_ in
> the continue block.
Chris,
I read your post twice, and I'm still not sure *exactly* what
you want. Could you submit some code to demonstrate what you
get, and what you want? I have a feeling that others are having
the same problem here.
[Note: the feeling comes from running the beta of Gisle's
LWP::Psychic module I learned about today. :-) ]
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5036
**************************************