[10668] in Perl-Users-Digest
Perl-Users Digest, Issue: 4260 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 19 21:07:31 1998
Date: Thu, 19 Nov 98 18:01:29 -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 Thu, 19 Nov 1998 Volume: 8 Number: 4260
Today's topics:
trouble storing array of objects (Bill McGonigle)
Unified Scripting Environment? Re: A Smaller Tcl - S2K? fleye@my-dejanews.com
Using an unknown var in search... <splinter@monmouth.com>
Re: Using an unknown var in search... (Tad McClellan)
wierd perl5.04004 behaviour <mathias@singapura.singnet.com.sg>
Win32::AdminMisc documentation <daveknight.com@usa.net>
XS_unpack_charPtrPtr ?? <hongy@bear.cs.ucla.edu>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 19 Nov 1998 20:37:20 -0500
From: bill@artoo.hitchcock.org (Bill McGonigle)
Subject: trouble storing array of objects
Message-Id: <bill-1911982037200001@dhcp418-21.dhcp.hitchcock.org>
I seem to have hit a small roadblock on my first multi-package OO perl project.
I've got a couple classes, called Patient and Lab;
Patient starts off like:
package DHMC::Patient;
require DHMC::Lab;
require Exporter;
require DynaLoader;
@ISA = (Exporter, DynaLoader);
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
#I declare some scalars e.g.:
$self->{status} = "";
#And then 'labs', which will hold some Lab objects:
$self->{labs} = [];
bless ($self,$class);
return $self;
}
#Lab is just scalars:
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{test} = "";
#... more scalars
bless($self,$class);
return $self;
}
# Later, I create a Lab and fill in the scalars
my $new_lab = DHMC::Lab->new();
$new_lab->test($raw_lab[5]);
# using
# and
sub test {
my $self = shift;
if (@_) {
my $temp = shift;
if (defined($temp)) {
$self->{test} = $temp;
}
}
return $self->{test};
}
# so far, so good, I think
# Then I tack it on to the patient
$patient->add_lab($new_lab);
# which calls
sub add_lab {
my $self = shift;
my $temp = shift;
$self->{labs} = [$self->{labs},$temp];
return $self->{labs};
}
# The happens n times. Later I want to print them out. Having:
sub get_labs {
my $self = shift;
return $self->{labs};
}
# I do:
sub print_labs {
my $patient = shift;
my @labs = $patient->get_labs();
my ($lab);
foreach $lab (@labs) {
print $lab->test();
# etc
}
}
#which tells me:
Can't call method "test" on unblessed reference at
(the line with print $lab->test(); )
(F) A method call must know in what package it's supposed to run. It
ordinarily finds this out from the object reference you supply, but
you didn't supply an object reference in this case. A reference isn't
an object reference until it has been blessed. See perlobj.
# If I do:
print Dumper($lab);
I get:
$VAR1 = [
[
[
[],
bless( {
'accession_number' => '9831500773',
'normal_high' => 145,
'test' => 'NA',
'resulting_date' => '11/11/1998',
'normal_low' => 135,
'units' => 'MMOL/L',
'abnormal_flag' => '',
'note' => 'THIS IS A TEST.',
'status_code' => 'C',
'result' => 140
}, 'DHMC::Lab' )
],
bless( {
'accession_number' => '',
'normal_high' => '',
'test' => 'KA+',
'resulting_date' => '',
'normal_low' => '',
'units' => '',
'abnormal_flag' => '0',
'note' => '',
'status_code' => 'S',
'result' => ''
}, 'DHMC::Lab' )
],
bless( {
'accession_number' => '9831000873',
'normal_high' => 107,
'test' => 'CL',
'resulting_date' => '11/06/1998',
'normal_low' => 98,
'units' => 'MMOL/L',
'abnormal_flag' => 'L',
'note' => '',
'status_code' => 'C',
'result' => 90
}, 'DHMC::Lab' )
];
which tells me that it's not coercing $patient->labs into an array, I
think. It also tells me I may have missed something fundamental as to how
to deal with these objects.
I've seen mention of a syntax like $patient->lab[-1]->test() (can somebody
explain this notation's numbering?). If I have to use that, how can I get
the proper number of elements from it? I really like foreach loops if you
didn't notice. :)
Anyway, I've been through two pink and four blue books and perltoot and
perlbot and the more than I wanted to know pages, and dejanews, and still
am missing something.
Thanks to he (english neuter form) who can show me where I screwed up.
Thanks,
-Bill
--
-----
Bill.McGonigle-spamers-suck@Hitchcock.org
Dartmouth Hitchcock Medical Center Clinical Computing
------------------------------
Date: Fri, 20 Nov 1998 01:17:11 GMT
From: fleye@my-dejanews.com
Subject: Unified Scripting Environment? Re: A Smaller Tcl - S2K?
Message-Id: <732fu9$elj$1@nnrp1.dejanews.com>
In article <3653FCC7.46C2D62E@equi4.com>,
Jean-Claude Wippler <jcw@equi4.com> wrote:
> Imagine the following "Scripting 2000 toolbox", let's call it "S2K":
How about USE -- a highly customizable, scalable and fully componentized
"Unified Scripting Environment"!
> - A small set of independent function groups, such as hashing, base io,
> dynamic vectors, string utilities, regex, etc. Coded in C or C++.
> And another one who's time has come, IMO: memory mapped file access.
> - This core is based on proven software, aiming for maximum MODULARITY.
> Function groups are planned to evolve / be-added right from the start.
> - Choose C++ as interface language, and make very careful use of the
> template mechanism to avoid inheritance and virtual members, except
> where these mechanisms add value and *increase* performance.
> - Use the virtual dispatch mechanism of C++ as the binding layer for
> extensions. Add wrappers for C and Tcl/Python specific aspects.
> - Consider using C++ exceptions, if this does not prevent portability.
> A major gain would be to benefit from C++'s automatic stack cleanup.
> - Use C++ class wrappers to take care of all reference-counting details.
> This is easy, automatic reference counting works really well with C++.
If you want to use C++ as a tool box builder, I could not agree more that we
should take advantage of the template mechanism for genericity and
performance, however I'd stay away from the C++ exceptions, which is an
unnecessary performance (space and time) and portability burden for generic
library builder. The script exception mechanism itself should be
independent/orthogonal of that for tool box/extension language.
> The underlying assumptions are, that general-purpose scripting languages
> all have very similar requirements (hashing, string handling, dynamic
> vectors are all good examples of this), and that a common code base will
> attract maximum attention from the most talented minds in the world to
> optimize and take such generic function groups to new heights.
Agreed.
> How does this help scripting in general? How about finding new ways to
> package and deploy extensions, for ALL languages? Or installers which
> benefit from common code? Or more generalized test/porting tools? Or
> pluggable string/container implementation experiments? Or combining
> efforts to port to embedded/palmtops? The list is really endless...
We should learn from the JVM fiasco, and maintain ONE open source USE
VM/plugin (itself modularized with language specific part in extensions), so
our USE bytecode really runs EVERYWHERE!
> Ok, but isn't Perl the big evil we all desperatly want to go away? Nah,
> there is plenty of room on this planet. The current investment in Perl
> is most likely a multiple of Tcl and Python taken together. It is not
> realistic to expect anyone to destroy that investment. And who knows,
> people from the Perl community might well embrace this approach, and
> even contribute substantially. Either way is fine with me. In terms of
> technology (read: performance), Perl still has quite a lot to offer.
I'd include Perl in USE too.
> All of today's modern scripting languages have more communality than
> fundamental differences, despite everyone's personal preferences and
> those ever-recurring discussions of language syntax and semantics.
My contribution to this USE idea: make language parsers/compilers itself
modules/extensions/components of USE. So people can choose their favorite
syntax and semantics, while maximizing the reusability of the underlying
generic facilities (general data structures (dynamic hash and vectors, etc.)
and tools (regexp, Tk, etc.), bytecode, plugin/VM)! Tcl/Tk is a logical
starting point because of its meta language nature.
Imagine:
People like me can use:
Practcl (Perl in USE, Practical is the first word of Perl!) or
Pytcl (Python in USE, still pronounced as Python, a mandatory language
to learn for all my employees, if I ever have some :-)
Language purists can use:
Scl (scheme in USE, pronounced as sicko :-)
Scientists/engineers can use:
Mathcl (MATLAB in USE! make sure the M-files work under it:-)
E-Music composers can use:
Musicl (A multimedia scripting language for MIDI/MOD!)
Religious workers can use:
Miracl (to illustrate/glorify the creation of the universe of course!:-)
or we can just use the smaller Tcl - small, simple and embeddable!
And they ALL run in ALL browsers on ALL platforms! And because of the
component nature of USE only necessary components are installed for a
particular usage!
> Let's try to move forward. Let's share and combine the best there is.
> Not as a goal, but simply as a side effect of striving for excellence.
> Scripting, its flexible and portable solutions, will benefit from it.
Excellent post, Jean-Claude. Looks like my dream is also shared by others.
Let's start from building a high performance generic scripting template
library. I hope this common dream will bring the three scripting amigos
(Guido, John and Larry) together to make the world a better place for the
next century! Heck, let's start a "Unified Scripting Environment Consortium"
(USEC), while we are at it...
Fly.
P.S. Although I haven't programmed extensively in Python, it strikes me as a
very clean and versatile scripting language (if you haven't, check it out at
http://www.python.org) (I have >10k lines of commercial coding experience in
each of C++, Perl and Tcl). The thing in Python that irks me the most is the
overloaded ":" usage (used for list slicing, dictionary definition and
indentation/nesting) which is only good for Python obfuscation and makes it
difficult to determine the correct indentation levels in an editor, unless
you have an elaborate Python mode with a Python parser builtin! Yuck!!! (real
world algorithms COULD have very complicated and deep nesting levels, make
them a nightmare to view/edit/maintain in Python) Come on, Guido, just use
the ONE TRUE curly brackets for indentation!
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 19 Nov 1998 19:13:15 -0500
From: "Matt" <splinter@monmouth.com>
Subject: Using an unknown var in search...
Message-Id: <732c1q$qfr$1@news.monmouth.com>
Hi...
I know this is impossible to do the way I have it but would anyone suggest a
way to do so...here is the code I have...
foreach $thing(@array)
{
$thing =~ s/<.*?$thing>.*?<.*?$thing>//i;
}
So the values I get out of that array I want to be used in finding those
values in some text and deleting :
<tag variable>html stuff<tag variable>
that whole block of stuff upon request....does anyone have any suggestions?
If it happens to be in some perl manual I'm sorry, I looked in most but
maybe I missed it.
-Matt
------------------------------
Date: Thu, 19 Nov 1998 19:48:46 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Using an unknown var in search...
Message-Id: <uph237.ml3.ln@flash.net>
Matt (splinter@monmouth.com) wrote:
: I know this is impossible to do the way I have it but would anyone suggest a
: way to do so...here is the code I have...
: foreach $thing(@array)
: {
: $thing =~ s/<.*?$thing>.*?<.*?$thing>//i;
: }
: So the values I get out of that array I want to be used in finding those
: values in some text and deleting :
: <tag variable>html stuff<tag variable>
: that whole block of stuff upon request....does anyone have any suggestions?
--------------------
#!/usr/bin/perl -w
@array = ( 'tag', 'variable' );
while (<DATA>) {
foreach $pat (@array) { # '$thing' is hopelessly non-descriptive
s#<$pat>.*?</$pat>##gi;
}
print;
}
__DATA__
<goodstuff>
<tag>html stuff</tag><tag>html stuff</tag>
<more good stuff>Good</more good stuff>
<variable>html stuff</variable><variable>html stuff</variable>
<yet more good stuff>Yet</yet more good stuff>
--------------------
But that has several Bad Things going for it:
1) inefficient, see the FAQ below
2) you *CANNOT* parse HTML with a regex, it will work on some legal
HTML and fail on other legal HTML. Use HTML::Parse instead.
3) fails on multiline elements:
eg:
<tag>hello
world</tag>
: If it happens to be in some perl manual I'm sorry, I looked in most but
: maybe I missed it.
Perl FAQ, part 6:
"How do I efficiently match many regular expressions at once?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 20 Nov 1998 01:40:50 GMT
From: Mathias Koerber <mathias@singapura.singnet.com.sg>
Subject: wierd perl5.04004 behaviour
Message-Id: <732hb2$223$1@mawar.singnet.com.sg>
I have detected very wierd behaviour on one my systems:
Given the following script:
------------------------------------------
#!/usr/bin/perl
#
# usage: grepmail pattern file(s)
#
# This script will inspect the given syslogfiles for all email containing pattern.
# as an extension to the normal grep, it will extract the QueueID of the mail from
# found records, and run a second grep on these QueueIDs, yielding the final output..
$pattern = shift(@ARGV);
undef %QIDs;
@files = @ARGV;
@ARGV;
# first run
while (<>) {
local($qid);
next unless /$pattern/;
($qid) = m|sendmail\[\d+\]\:\s+(\[A-Z]+[0-9]+)\:|;
$QIDs{$qid}++;
}
@ARGV=@files; # restore the files listed..
while (<>) {
local($thisqid);
($thisqid) = (/sendmail\[\d+\]\:\s+(\[A-Z]{3}[0-9]{5})\:/);
print if ($QIDs{$thisqid});
}
--------------EO Script------------------
the debugger acts like this:
----------------------------
$ perl -d ./grepmail "canlah" /var/log/messages
Loading DB routines from perl5db.pl version 1.01
Emacs support available.
Enter h or `h h' for help.
main::(./grepmail:9): $pattern = shift(@ARGV);
DB<1> s
main::(./grepmail:11): undef %QIDs;
DB<1>
main::(./grepmail:13): @files = @ARGV;
DB<1>
main::(./grepmail:14): @ARGV;
DB<1>
main::(./grepmail:25): @ARGV=@files; # restore the files listed..
DB<1>
main::(./grepmail:18): local($qid);
DB<1>
main::(./grepmail:19): next unless /$pattern/;
DB<1> q
----------------------------------------------------
Why is it executing line 25 before going into the while loop at like 18?
# perl -V
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
Platform:
osname=linux, osvers=2.0.33, archname=i586-linux
uname='linux darkstar 2.0.33 #3 fri feb 20 21:11:15 cst 1998 i586 unknown '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2', gccversion=egcs-2.90.27 980315 (egcs-1.0.2 release)
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
stdchar='char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
libc=/lib/libc.so.5.4.38, so=so
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Built under linux
Compiled at Mar 22 1998 23:24:20
@INC:
/usr/lib/perl5/i586-linux/5.00404
/usr/lib/perl5
/usr/lib/perl5/site_perl/i586-linux
/usr/lib/perl5/site_perl
.
Any help is appreciated.
--
Mathias Koerber | Tel: +65 / 471 9820 | mathias@staff.singnet.com.sg
SingNet NOC | Fax: +65 / 475 3273 | mathias@koerber.org
Q'town Tel. Exch. | PGP: Keyid: 768/25E082BD finger mathias@singnet.com.sg
2 Stirling Rd | 1A 8B FC D4 93 F1 9A FC BD 98 A3 1A 0E 73 01 65
S'pore 148943 | Disclaimer: I speak only for myself
On a clear disk you can seek forever.
------------------------------
Date: Thu, 19 Nov 1998 15:40:51 -0800
From: "Dave Knight" <daveknight.com@usa.net>
Subject: Win32::AdminMisc documentation
Message-Id: <732bi3$l9v@news.or.intel.com>
Here's a nice newbie question:
How do I find documentation for the Win32::AdminMisc module? Doing a
recursive search for AdminMisc using perldoc comes up empty.
A more general question is, where do you find more extensive docs (other
than perldoc) on any particular module?
Thanks in advance for any nudges in the right direction.
-Dave Knight
------------------------------
Date: 20 Nov 1998 00:12:40 GMT
From: Hong Yuan <hongy@bear.cs.ucla.edu>
Subject: XS_unpack_charPtrPtr ??
Message-Id: <732c5o$mps$1@news.cs.ucla.edu>
Hi,
I'm learning XS. I have in xs file this:
int
foo(a, b)
int a;
char** b;
It compiled OK. When I tried to call foo, I got:
Unresolved symbol: XS_unpack_charPtrPtr
Where's XS_unpack_charPtrPtr?
Thx!
Hong.
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4260
**************************************