[24767] in Perl-Users-Digest
Perl-Users Digest, Issue: 6920 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 27 06:06:05 2004
Date: Fri, 27 Aug 2004 03:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 27 Aug 2004 Volume: 10 Number: 6920
Today's topics:
anybody have experience in url decode (included chinese <end@dream.life>
Re: exit(), die, ?? <Joe.Smith@inwap.com>
Re: HTML::Parser <ebohlman@omsdev.com>
Re: HTML::Parser <zebee@zip.com.au>
Re: HTML::Parser <tassilo.von.parseval@rwth-aachen.de>
Re: HTML::Parser <zebee@zip.com.au>
Re: HTML::Parser <tassilo.von.parseval@rwth-aachen.de>
Re: Larry Wall & Cults <gneuner2/@comcast.net>
Re: Larry Wall & Cults <gneuner2/@comcast.net>
Re: Larry Wall & Cults <rich.teer@rite-group.com>
Re: Larry Wall & Cults <tassilo.von.parseval@rwth-aachen.de>
Re: Larry Wall & Cults (norman werner)
Re: Mystery with Files with loop (Anno Siegel)
Re: Mystery with Files with loop <Joe.Smith@inwap.com>
Re: Net::Ping::External doesn't honor timeout or count <wherrera@lynxview.com>
Re: Net::Ping::External doesn't honor timeout or count <someone@example.com>
Object Oriented programs, Perl and others <mb@uq.net.au.invalid>
Re: Object Oriented programs, Perl and others <uri@stemsystems.com>
Re: performance surprise -- why? <someone@example.com>
Re: performance surprise -- why? <abigail@abigail.nl>
Problem on Debian Linux Installing DBD-mysql <hal@thresholddigital.com>
Reference to functions <corleone@godfather.com>
Re: Reference to functions <josef.moellers@fujitsu-siemens.com>
Re: Xah Lee's Unixism <spam@mouse-potato.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 27 Aug 2004 12:39:28 +0800
From: Alont <end@dream.life>
Subject: anybody have experience in url decode (included chinese gb2312 character) ?
Message-Id: <4130b9f1.80367562@130.133.1.4>
I use a "CGI_Lite" module to decode a url included chinese
character(gb2312) but it's result is some bad code,
use CGI_Lite;
$cgi = new CGI_Lite;
$cgi->set_platform ($Windows);
$string=
"http://www.google.com/search?sourceid=navclient&hl=zh-CN&ie=UTF-8&q=%E5%9C%A8%E7%BA%BF%E8%AF%8D%E5%85%B8";
$decoded_string = url_decode ($string);
print $decoded_string;
the result:
http://www.google.com/search?sourceid=navclient&hl=zh-CN&ie=UTF-8&q=在线词典
--
Your fault as a Government is My failure as a citizen
------------------------------
Date: Fri, 27 Aug 2004 10:00:02 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: exit(), die, ??
Message-Id: <CCDXc.318204$a24.265394@attbi_s03>
Tony McGuire wrote:
> I tried 'die' several times based on example code I found.
> I always got 'premature end of script headers' as a error. Looking at
> the logs the error pointed to the 'die' section.
That's what you get for outputting text that does not conform to CGI
requirements. You need to fix that. The "Content-type:" header is required.
use CGI::Carp qw(fatalsToBrowser);
die "I give up." if $something == $not_right;
-Joe
------------------------------
Date: 27 Aug 2004 04:06:58 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: HTML::Parser
Message-Id: <Xns9551EC02EB6AAebohlmanomsdevcom@130.133.1.4>
Zebee Johnstone <zebee@zip.com.au> wrote in
news:slrncit7rb.2nn.zebee@zeus.zipworld.com.au:
> Is there a way to associate the tag text with the tag, and only
> use that?
You might want to try HTML::TokeParser instead (it's included with the
HTML::Parser distribution). It's a "pull" parser rather than a "push" one;
rather than it calling your code in response to tags and text, you call it
to get the next "token" which can be a start tag, text, end tag, etc. and
then decide what to do with it. Using it is similar to reading through a
file in a loop.
------------------------------
Date: Fri, 27 Aug 2004 05:27:08 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: HTML::Parser
Message-Id: <slrncith6r.7a5.zebee@zeus.zipworld.com.au>
In comp.lang.perl.misc on 27 Aug 2004 04:06:58 GMT
Eric Bohlman <ebohlman@omsdev.com> wrote:
> You might want to try HTML::TokeParser instead (it's included with the
> HTML::Parser distribution). It's a "pull" parser rather than a "push" one;
> rather than it calling your code in response to tags and text, you call it
> to get the next "token" which can be a start tag, text, end tag, etc. and
> then decide what to do with it. Using it is similar to reading through a
> file in a loop.
Bingo! Much easier to use and understand. Thanks.
Zebee
--
Zebee Johnstone (zebee@zip.com.au), proud holder of
aus.motorcycles Poser Permit #1.
"Motorcycles are like peanuts... who can stop at just one?"
------------------------------
Date: Fri, 27 Aug 2004 07:41:55 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: HTML::Parser
Message-Id: <2p7vt5Fhho9kU2@uni-berlin.de>
Also sprach Zebee Johnstone:
> In comp.lang.perl.misc on Thu, 26 Aug 2004 07:46:55 +0200
> Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote:
>>
>> <http://www.unisolve.com.au/perlmeme/tutorials/html_parser.html>
>
> I understand more now about it, but your tutorial doesn't cover the
> text, which I need.
>
> If I print out all the text elements:
>
> sub text {
> my($self, $origtext, $is_cdata) = @_;
> print "text [$origtext] \n";
> }
>
> then I get the text associated with the tags I'm after, but I get a lot
> of other text as well.
More specifically, you get all the plain text elements of the HTML file.
> Is there a way to associate the tag text with the tag, and only
> use that?
Yes, by keeping track in which tag the parser currently is.
> So a bit of HTML
> <a href="http://www.google.com"> Google </a> would have "Google"
> associated with "http://www.google.com"?
>
> ideally, I'd like to call the text subroutine from the start subroutine,
> and pass it a hash to put the text value in. And have it return that
> hash.
Those are handlers and they can't have such a return value. But you have
an object (the HTML::Parser object) in which you can store the data:
#!/usr/bin/perl -w
package MyParser;
use strict;
use base qw/HTML::Parser/;
sub start {
my ($self, $tagname, $attr) = @_;
if ($tagname eq 'a') {
# store the URL as key of a new hash-ref
# associated text not yet known, therefore undef
push @{ $self->{a} }, { $attr->{href} => undef };
$self->{in_a} = $attr->{ href };
}
}
sub end {
my ($self, $tagname) = @_;
delete $self->{in_a} if $tagname eq 'a';
}
sub text {
my ($self, $text) = @_;
if (exists $self->{in_a}) {
# text is between <a> and </a>
$self->{a}->[-1]->{ $self->{in_a} } = $text;
}
}
package main;
use Data::Dumper;
my $html = <<EOHTML;
<html>
<body>
<a href="http://www.first.com" target="bla">First link</a>
<a href="http://www.second.com">Second link</a>
</body>
</html>
EOHTML
my $p = MyParser->new;
$p->parse($html);
print Dumper $p->{a};
__END__
$VAR1 = [
{
'http://www.first.com' => 'One link'
},
{
'http://www.second.com' => 'Second link'
}
];
> It isn't clear to me what items the start subroutine knows about that
> it can pass to the text subroutine.
Handlers don't call each other. It's HTML::Parser's parse-routines that
call the handlers whenever they encounter a start or end tag, a text
block or a comment. Handlers are called as-soon-as-event-happens.
> IN the examples, it seems to use (text => [], '@{dtext}' ) as args to
> the text handler, but I've no idea where those come from at all, or
> what they are, or how to use them. I have the "$self" object, which I
> can pass to a subroutine but no idea how to get the things I need from
> it.
This $self object is the object you create with 'HTML::Parser->new'. Per
default it doesn't contain useful information. It holds the state of the
parser. But, as show above, you can abuse it as a cheap way of keeping
your own states. All I did was injecting two new member variables into
the object: $self->{in_a} which holds the URL when being inside an <a>
tag, otherwise this field does not exist. It is deleted in the
end-handler when $tagname is 'a'.
The second one is $self->{a}. This one is an array-ref of
hash-references. Each new URL/text pair is recorded in there and pushed
onto this array.
When '$p->parse' returns you look at '$p->{a}' and there you have the
data you want to extract.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 27 Aug 2004 06:54:47 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: HTML::Parser
Message-Id: <slrncitmb7.a6v.zebee@zeus.zipworld.com.au>
Bear with me please, I'm still getting to grips with a lot of notation
and ideas...
If that means I need to go read something to understand, please point me
at it!
In comp.lang.perl.misc on Fri, 27 Aug 2004 07:41:55 +0200
Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote:
> my ($self, $tagname, $attr) = @_;
> if ($tagname eq 'a') {
> # store the URL as key of a new hash-ref
> # associated text not yet known, therefore undef
> push @{ $self->{a} }, { $attr->{href} => undef };
OK, given your explanation below, I think I get this.
> sub text {
> my ($self, $text) = @_;
> if (exists $self->{in_a}) {
> # text is between <a> and </a>
> $self->{a}->[-1]->{ $self->{in_a} } = $text;
Why -1? I don't understand this line at all...
>
> The second one is $self->{a}. This one is an array-ref of
> hash-references. Each new URL/text pair is recorded in there and pushed
> onto this array.
>
> When '$p->parse' returns you look at '$p->{a}' and there you have the
> data you want to extract.
>
Zebee
------------------------------
Date: Fri, 27 Aug 2004 09:39:47 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: HTML::Parser
Message-Id: <2p86q5Fhq1agU1@uni-berlin.de>
Also sprach Zebee Johnstone:
> Bear with me please, I'm still getting to grips with a lot of notation
> and ideas...
>
> If that means I need to go read something to understand, please point me
> at it!
Your question is mostly about the data-structure that is used here. So
that would make it a perldsc/perlreftut/perlref-question.
> In comp.lang.perl.misc on Fri, 27 Aug 2004 07:41:55 +0200
> Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote:
>> my ($self, $tagname, $attr) = @_;
>> if ($tagname eq 'a') {
>> # store the URL as key of a new hash-ref
>> # associated text not yet known, therefore undef
>> push @{ $self->{a} }, { $attr->{href} => undef };
>
> OK, given your explanation below, I think I get this.
>
>> sub text {
>> my ($self, $text) = @_;
>> if (exists $self->{in_a}) {
>> # text is between <a> and </a>
>> $self->{a}->[-1]->{ $self->{in_a} } = $text;
>
> Why -1? I don't understand this line at all...
Previously I did this:
push @{ $self->{a} }, { $attr->{href} => undef };
This means: $self->{a} is an array-reference. The hash-reference
{ $attr->{href} => undef }
is pushed onto this array-ref which means it is now the last element.
However, the hash-ref is incomplete. The value associated with they key
$attr->{href} is undef because we can't yet know the text enclosed in
<a> and </a>. But later we will (namely in the text() handler).
Once text is called, it's checked that we are inside <a>|</a>. If we
are, we finally have the text portion we wanted. We know that the
incomplete hash-reference is the last element in @{ $self->{a} }. And so
it becomes:
$self->{a}->[-1]
which is our previously created hash-reference. Only the value is
updated. The key was stored in $self->{in_a}:
$self->{a}->[-1]->{ $self->{in_a} } = $text;
I admit that the data-structure I used is not ideal. If you are sure
that the URLs defined in <a> tags are unique, you can do away with the
array-ref altogether:
sub start {
my ($self, $tag, $attr) = @_;
if ($tag eq 'a') {
$self->{in_a} = $attr->{href};
}
}
sub text {
my ($self, $text) = @_;
if (exists $self->{in_a}) {
$self->{a}->{ $self->{in_a} } = $text;
delete $self->{in_a};
}
}
We didn't need the end-handler as I just realized. We can also delete
$self->{in_a} in text().
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 27 Aug 2004 00:50:58 -0400
From: George Neuner <gneuner2/@comcast.net>
Subject: Re: Larry Wall & Cults
Message-Id: <0cfti0hu2ps1l930fea0050vo76jeb2drh@4ax.com>
On Thu, 26 Aug 2004 13:09:32 -0700, Jeff Shannon <jeff@ccvcorp.com>
wrote:
>The Cult did have an earlier incarnation as Southern Death Cult.
And Blue Oyster Cult was originally Soft White Underbelly.
George
--
for email reply remove "/" from address
------------------------------
Date: Fri, 27 Aug 2004 01:00:33 -0400
From: George Neuner <gneuner2/@comcast.net>
Subject: Re: Larry Wall & Cults
Message-Id: <tkfti0laq7ebn1t9374679u6tts20ba5n5@4ax.com>
On 25 Aug 2004 14:56:06 -0700, xah@xahlee.org (Xah Lee) wrote:
>
> Unixism
>
"Isms", in my opinion, are not good. A person should not believe in
an "ism". He should believe in himself.
Ferris Bueller
--
for email reply remove "/" from address
------------------------------
Date: Fri, 27 Aug 2004 05:35:42 GMT
From: Rich Teer <rich.teer@rite-group.com>
Subject: Re: Larry Wall & Cults
Message-Id: <Pine.SOL.4.58.0408262235270.568@zaphod.rite-group.com>
On Fri, 27 Aug 2004, Reynir Stefnsson wrote:
> And then there's this crazy little thing called love...
Nah - that was Queen!
--
Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming",
published in August 2004.
President,
Rite Online Inc.
Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
------------------------------
Date: Fri, 27 Aug 2004 07:13:19 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Larry Wall & Cults
Message-Id: <2p7vt5Fhho9kU1@uni-berlin.de>
Also sprach Otto Wyss:
> Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote:
>
>> It would, if anyone could take Xah Lee Loo seriously. But really, no one
>> can. He's more like the court jester, creeping out of the dark every so
>> and so months. We're all very much enjoying his sporadic shows. Really.
>>
>> ;-)
>>
> No offense but could you add some references so anyone can make up is
> own opinion?
For instance this one:
<http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&th=ced06f6c6a36927f&rnum=4>
Pay particular attention to the fact that he's whining about a certain
feature of a Perl module but posts not only in comp.lang.perl.misc but
also in the scheme, lisp, python and ruby group.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 27 Aug 2004 00:31:57 -0700
From: norman.werner@student.uni-magdeburg.de (norman werner)
Subject: Re: Larry Wall & Cults
Message-Id: <b301fb47.0408262331.1e4d04eb@posting.google.com>
Albert Reiner <areiner@tph.tuwien.ac.at> wrote in message news:<vw8fz6938pw.fsf@berry.phys.ntnu.no>...
> ["Michiel Borkent" <borkent@cs.utwente.nl>, Thu, 26 Aug 2004 13:35:38 +0200]:
> > LISP and Esperanto: my favorite languages.
>
> Ankaux miaj - krom, eble, ankaux la Haskella.
>
> Stranga koncentrigxo de verdlingvanoj cxe cll, cxu ne?
>
> Albert.
estas koncentrig:o. Ambau: lingvoj estas elektata de inteligentaj homoj :)
Espereble mi ne g:ustas - ne mi s:atas induktitan konkludon pri homaro.
Norman
------------------------------
Date: 27 Aug 2004 08:58:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Mystery with Files with loop
Message-Id: <cgmt3b$37a$1@mamenchi.zrz.TU-Berlin.DE>
Rob L <lindsey_rob@hotmail.com> wrote in comp.lang.perl.misc:
> I have a program that I have written to read a few files for
> information and then takes some of that information and puts the data
> into arrays based on certain things. What I did was to run this
^^^^^^
> program out of CRON on a Unix system every few mins. I figured out
> today that I needed this job to almost continuously so I added a while
> loop to the code and was testing it to see how it would work. Well
> what I found out is that after the arrays are created I write the data
> to a "temp" file and then copy/move the data file to the real name the
> data is appending to the "real" file instead of replacing it.
The "mv" command that you have been using doesn't do that. Nor
does the Perl "rename" function you should have been using.
[snip lots of ugliness]
I suspect that you forgot to clear those arrays you are using, or
rather that you failed to declare them lexically in an appropriate
scope. I'm not going to dig through 360 lines of code to verify.
If you want your code checked, make a short excerpt that shows the
behavior you don't understand. Dumping the whole program to the
newsgroup is the wrong kind of laziness.
Anno
------------------------------
Date: Fri, 27 Aug 2004 09:52:52 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Mystery with Files with loop
Message-Id: <UvDXc.76875$mD.71783@attbi_s02>
Rob L wrote:
> data is appending to the "real" file instead of replacing it.
You mean that the old data and the new data are replacing it,
since the old data is never removed from your arrays.
> foreach $aim (@prob_east) {
> print PROBFILE "$outData{$aim}\n";
> }
> foreach $aim (@prob_central) {
> print PROBFILE "$outData{$aim}\n";
> }
> foreach $aim (@prob_west) {
> print PROBFILE "$outData{$aim}\n";
> }
> foreach $aim (@prob_unk) {
> print PROBFILE "$outData{$aim}\n";
> }
foreach $aim (@prob_east, @prob_central, @prob_west, @prob_unk) {
print PROBFILE "$outData{$aim}\n";
}
@prob_east = @prob_central = @prob_west = @prob_unk = ();
-Joe
------------------------------
Date: Thu, 26 Aug 2004 22:46:22 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: Net::Ping::External doesn't honor timeout or count
Message-Id: <1MednWQL--Y9IbPcRVn-tg@adelphia.com>
Stuart Kendrick wrote:
> hi,
>
> i'm using Net::Ping::External to do my pings. i would like to fiddle
> with its 'timeout' and 'count' parameters ... but i don't seem to be
> able to. no matter how i set them, i get the same results: a timeout
> of 10 seconds and a count of 1.
>
...
> i've replicated this issue in the following environments:
> perl-5.8.5, Net-Ping-External-v0.11, SuSE 9.1
> perl-5.8.3, Net-Ping-External-v0.11, SuSE 8.2
>
> has anyone else seen this issue?
>
Yes, with Mandrake. But:
From the docs:
-----------------------
Linux
Tested OK on Debian 2.2 and Redhat 6.2. It appears that different
versions of Linux use different versions of ping, which support
different options. Not sure how I'm going to resolve this yet; for now,
all the options but count are disabled.
------------------------------
Date: Fri, 27 Aug 2004 08:06:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Net::Ping::External doesn't honor timeout or count
Message-Id: <8YBXc.19017$A8.10967@edtnps89>
Stuart Kendrick wrote:
>
> i'm using Net::Ping::External to do my pings. i would like to fiddle
> with its 'timeout' and 'count' parameters ... but i don't seem to be
> able to. no matter how i set them, i get the same results: a timeout
> of 10 seconds and a count of 1.
Since Net::Ping::External is just using your system's ping command have you
tried running ping with qx//? Have you read the man page for ping?
man ping
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 27 Aug 2004 15:06:00 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Object Oriented programs, Perl and others
Message-Id: <cgmffp$cg7$1@bunyip.cc.uq.edu.au>
Hi all,
I've been spending a lot of time lately writing a lot of objects for a project
here (so far about 60 objects and counting), and while I've been considering
security the whole way I've started thinking one level down on how to secure
objects from direct alteration if they were used as a library in some other
code. (At the moment this isn't _really_ an issue as the packages are not
available to users unless they go through controlled programs that don't allow
unknown code to run).
After tinkering, I've come up with the following pseudo-rules (please correct me
if I'm wrong here, and preferably give me pointers :)
1. If an object inherits from another object (in perl), it is free to
change/override any sub inside the parent.
2. There is no way to stop code from altering a class directly (eg, by doing
something like 'sub Object::_internal { something_unexpected() }'
3. The fixes I've so far run across (my'd hashes keyed on blessed references to
store instance data instead of using hashes for the base instance structure,
my'd subroutines for truly private methods) work (well, as far as they can
considering 1 and 2) but make inheritance an absolute nightmare - children can't
get hold of parent's protected data. Writing accessor methods for them is
problematic because of 2 - the accessor can be replaced to return something else.
4. Even if perl strictly adhered to OO paradigms I've learnt, some of these
problems are very hard to fix.
I've been thinking of theoretical ways to fix problems like this, and my
amateurish ideas so far have been:
1. Closing packages - from then on, no other code can enter that package's
namespace to specify subs, ie this:
package Example is closed; # Made up syntax - maybe should be fatal if the
# Example namespace already exists
our($Bar) = '123';
sub foo { ... }
package main;
sub Example::foo { ... } # Fatal - modify closed package
sub Example::other { ... } # Fatal - add to closed package
$Example::Bar = '321'; # OK - not changing a sub
package OtherExample;
use base qw/Example/;
sub foo { ... } # OK - this is an override, doesn't
# alter the Example package
This could be expanded to making packages 'append only' (only new subs added) as
well etc etc.
2. Closing subs - from then on, child packages and external code cannot override
a particular sub:
package Example;
sub foo is closed { ... } # More made up syntax. Maybe a warning if
# Example::foo is already defined
sub bar { ... }
package OtherExample;
use base qw/Example/;
sub foo { ... } # Fatal - the sub is closed and cannot be
# overriden, even by children
sub bar { ... } # OK
package main;
sub Example::foo { ... } # Fatal - same reason as above
3. 'Closed Object Families' or 'Willed Inheritance'. This one breaks the idea
that a parent need not know anything about its children a bit, but it limits who
can inherit from it:
package Example wills qw(OtherExample # Made up syntax - 'wills'
MoreExamples); # as in 'I hereby will my
# stuff to the following
# children...'
....
package MoreExamples;
use base qw/Example/; # OK - this is one of our 'trusted' children
....
package UnexpectedExample;
use base qw/Example/; # Fatal - not one of our trusted children, not allowed
# to inherit.
Using mixes of these, you can start to be confident to write accessors for
objects for finding out if they can do something potentially dangerous, or for
accessors to find out parameters for potentially dangerous actions, eg:
package Example is closed, wills qw(OtherExample);
my %Private;
sub new {
my $class = shift;
my $self = bless('', $class); # short version :)
$Private{$self} = {CanDelete => 0,
ID => 'someid'};
return $self;
}
sub can_delete is closed {
my $self = shift;
return 0 if not exists $Private{$self}; # Safe default
return $Private{$self}{CanDelete};
}
sub do_delete {
my $self = shift;
return 0 if not $self->can_delete;
# Do the delete...
return 1;
}
Now instances of Example and OtherExample can safely assume that:
$eg->can_delete
hasn't been overridden like:
sub Example::can_delete { return 1 }
(and do_delete hasn't been modified by 'untrusted' code), so can be used in
arbitrary code as library code (...I think :) )
This is all just musings off the top of my head - for all I know perl has some
of this already that I don't know about, and I haven't descended to the level
below (how can I be sure the user loaded the right module and not something from
a private directory etc), _and_ nothing here defines what happens if a package
tries to inherit from a package that has inherited from a _willed_ package (sheesh!)
All up I think I've been thinking too much about this stuff anyway :)
MB
------------------------------
Date: Fri, 27 Aug 2004 06:42:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Object Oriented programs, Perl and others
Message-Id: <x7hdqpnkup.fsf@mail.sysarch.com>
wait for perl6. it will have all that you ask for and more. perl5 won't
ever have it but you can use modules that do support some of those
ideas. also get the book 'object oriented perl' by damian conway. it
will teach you all you need to know about OO perl.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 27 Aug 2004 07:15:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: performance surprise -- why?
Message-Id: <ncBXc.18795$A8.8617@edtnps89>
Joe Davison wrote:
>
> [snip]
>
> #!/usr/bin/perl
> use strict; use warnings; $| = 1;
> #use Vi::QuickFix;
>
> use Benchmark ':all';
>
> use constant SIZE => 400_000;
> my ($ifile,$whatItWas);
> my ($str,$fsz);
>
> my $sequence = 'AGTACT';
>
> $ifile = shift @ARGV;
>
> unless (open INPUT, $ifile) {
> print STDERR "Can't open $ifile: $! \n";
^^^^^^^^^^^^
If the file can't be opened you print an error message but then you continue
on as if nothing had happened. You should do something that avoids trying to
read from an invalid filehandle, like exit() or die() maybe? You may also
want to use binmode() on the filehandle.
> }
>
> # Suck the whole ifile in for processing
>
> $str=<INPUT>; #toss the first record (the >CHR1v03212003 line in one case...)
> $whatItWas = $/;
> undef $/;
> $fsz = -s $ifile;
> $str = " " x $fsz; # preallocate filesized string!!
> $str = <INPUT>;
> $/ = $whatItWas;
The usual idiom to slurp a file is:
my $str = do { local $/; <INPUT> };
Another alternative (if you are going to stat the file anyway) is:
( my $fsz = read INPUT, my $str, -s INPUT ) or die "read error: $!";
$fsz == -s _ or die "Read $fsz bytes, expected " . -s _ . " bytes.\n":
It seems (at least to me) that since you are slurping the whole file,
preallocating the string is not required.
You may also want to have a look at the File::Slurp module which is AFAIK very
efficient.
> close INPUT;
>
> # Now do what we came for
>
> $str =~ s/\n//gs; # delete newlines
Use transliteration instead of substitution for speed:
$str =~ tr/\n//d; # delete newlines
John
--
use Perl;
program
fulfillment
------------------------------
Date: 27 Aug 2004 07:17:51 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: performance surprise -- why?
Message-Id: <slrncito0v.q3p.abigail@alexandra.abigail.nl>
Uri Guttman (uri@stemsystems.com) wrote on MMMMXIII September MCMXCIII in
<URL:news:x7sma9qx11.fsf@mail.sysarch.com>:
"" >>>>> "A" == Abigail <abigail@abigail.nl> writes:
""
"" A> Or one could just read the manual page. From 'man English':
""
"" A> PERFORMANCE
"" A> This module can provoke sizeable inefficiencies for regu
"" A> lar expressions, due to unfortunate implementation
"" A> details. If performance matters in your application and
"" A> you don't need $PREMATCH, $MATCH, or $POSTMATCH, try doing
""
"" A> use English qw( -no_match_vars ) ;
""
"" and as damian conway says (and i agree) they chose the wrong default for
"" that option. it should have been -use_match_vars and the default for
"" english should be to not alias them.
Well, yes, but Perl is full of things that are there because of wrong
decisions made in the past, and won't be changed for the sake of backwards
compatability.
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Fri, 27 Aug 2004 02:15:50 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Problem on Debian Linux Installing DBD-mysql
Message-Id: <kYCdnV-PPICbTLPcRVn-gw@comcast.com>
I have just recently switched to Libranet (basically Debian) Linux. I
cannot install the DBD-mysql mod on my system. It needs mysql_config,
which is not part of the mysql packages under Debian (or perhaps it's part
of a mysql package that doesn't look like it has to be installed?). I've
used apt-get to install the libdbd-mysql-perl, but that doesn't seem to
work. I'm not using the MySQL server on this computer, but I am using the
client to connect to MySQL on another system.
What can I do to get Perl working with MySQL on this system and (if anyone
knows) why doesn't Debian include mysql_config in their packages? It seems
like the kind of oversight that never makes it into Debian packaging.
Thanks for any help!
Hal
------------------------------
Date: Fri, 27 Aug 2004 16:14:06 +0900
From: Vito Corleone <corleone@godfather.com>
Subject: Reference to functions
Message-Id: <20040827161406.6c37d3e5.corleone@godfather.com>
Hi,
I tried to make a call a function by reference. Here is the code:
#!/usr/bin/perl
use strict;
sub show_a {
my ($txt) = @_;
print "show_a: $txt\n\n";
}
sub show_b {
my ($txt) = @_;
print "show_b: $txt\n\n";
}
sub show {
my ($type) = @_;
my $f = "show_" . $type;
$f->($type);
}
show("a");
But there was an error:
Can't use string ("show_a") as a subroutine ref while "strict refs" in
use at ./test.pl line 18.
How do I make this kind of call to function with 'use strict' turned on?
--Vito
------------------------------
Date: Fri, 27 Aug 2004 09:21:05 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Reference to functions
Message-Id: <cgmn80$o6u$1@nntp.fujitsu-siemens.com>
Vito Corleone wrote:
> Hi,
>=20
> I tried to make a call a function by reference. Here is the code:
>=20
> #!/usr/bin/perl
> use strict;
>=20
> sub show_a {
> my ($txt) =3D @_;
> print "show_a: $txt\n\n";
> }
>=20
> sub show_b {
> my ($txt) =3D @_;
> print "show_b: $txt\n\n";
> }
>=20
> sub show {
> my ($type) =3D @_;
> my $f =3D "show_" . $type;
> $f->($type);
> }
>=20
> show("a");
>=20
> But there was an error:
> Can't use string ("show_a") as a subroutine ref while "strict refs" in
> use at ./test.pl line 18.
>=20
> How do I make this kind of call to function with 'use strict' turned on=
?
Can't you use a hash?
#! /usr/bin/perl
use warnings;
use strict;
my %show =3D (
"a" =3D> sub {my ($txt) =3D @_;
print "show_a: $txt\n\n";
},
"b" =3D> sub {my ($txt) =3D @_;
print "show_b: $txt\n\n";
}
);
sub show {
my ($type) =3D @_;
$show{$type}($type);
}
show("a");
Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 27 Aug 2004 11:50:26 +0200
From: Pascal Bourguignon <spam@mouse-potato.com>
Subject: Re: Xah Lee's Unixism
Message-Id: <878yc0ucyl.fsf@thalassa.informatimago.com>
Kenny Tilton <ktilton@nyc.rr.com> writes:
> >>What you mean with Unixism?
> > repeated accidents. Such a tool would
> > first chop off the user's brain, molding
> > a mass of brainless imbeciles and
> > microcephalic charlatans the likes of
> > Larry Wall and Linus Torvald jolly
> > Server: Apache/2.0.50 (Fedora)
> > ^^^^^^^^^^^^^^^^^^^^^^
>
> So you like my approach, which is to condemn things they have never used?
>
> :)
No, that of no more using things that you condemn.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6920
***************************************