[10089] in Perl-Users-Digest
Perl-Users Digest, Issue: 3682 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 10 15:07:55 1998
Date: Thu, 10 Sep 98 12:00:19 -0700
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, 10 Sep 1998 Volume: 8 Number: 3682
Today's topics:
Absolute and Relative paths <michael@holdendesign.com>
CGI hang under mod_perl (?) <johns@oxygen.stx.com>
Re: Efficiency of subject line change program (Sean McAfee)
Interactive Perl without stinking braces a la Python dn5006@my-dejanews.com
Re: Looping and grep problem <sam@peritas.com>
Re: Objects & type checking <tchrist@mox.perl.com>
Re: Objects & type checking <eashton@bbnplanet.com>
Re: Objects & type checking <mark@satch.markl.com>
Re: pass on value to subroutine call <aqumsieh@tigre.matrox.com>
Re: Perl "mkdir" function <sam@peritas.com>
Re: Perl & Java - differences and uses <jdporter@min.net>
Re: Perl & Java - differences and uses <borg@imaginary.com>
Re: Perl & Java - differences and uses <jdporter@min.net>
Re: Perl & Java - differences and uses <borg@imaginary.com>
Re: Perl/Html - mixing text and graphics (David A. Black)
Re: replacing text in a string <sam@peritas.com>
Tokenizer in Perl... <jian@cisco.com>
Re: Tokenizer in Perl... (Mike Stok)
Re: vt520 emulation. ()
win32::internet question <markw@nc.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 Sep 1998 11:16:50 -0700
From: Michael Holden <michael@holdendesign.com>
Subject: Absolute and Relative paths
Message-Id: <35F81792.FFD7BB9C@holdendesign.com>
Hello, fellow PERLers.
I have to change all <a href> links from absolute paths to relative
paths on roughly 5000 files. In the spirit of not reinventing the wheel
I was wondering if anyone knew if there were scripts or modules out
there that can assist with this.
You can reply off-list if you want. My email address is
michael@holdendesign.com.
Thanks in advance!
Michael
"Don't stray off the path!" --Gandalf
------------------------------
Date: 10 Sep 1998 14:03:21 -0700
From: Steve Johns <johns@oxygen.stx.com>
Subject: CGI hang under mod_perl (?)
Message-Id: <4yzpc7vfxi.fsf@oxygen.stx.com>
Hi.
I've got a CGI script which assembles a document from a database and
outputs it to a Web brower. It works fine under normal CGI.
Under mod_perl (and Apache 1.3.1), the document arrives in the
browser, and then the browser stalls - as if it were still waiting for
the rest of the document.
>From the command line, the output is all fine as far as I can see.
Could someone please give me some clues on what might be causing this?
- sj
------------------------------
Date: Thu, 10 Sep 1998 18:26:57 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Efficiency of subject line change program
Message-Id: <RRUJ1.2026$F7.8610248@news.itd.umich.edu>
In article <01bddce0$e261fee0$8395cdcf@hp-customer>,
George H <george@tapestry.net> wrote:
[snip -- wrote mail-processing script]
>The end users love it ... but since I am relatively new to
>programming and perl, I was wondering if they way I did it is not very
>efficient. I mean 'printing' every line to a mail pipe may be bad use of
>resources.
No, that's a perfectly proper use of pipes.
>I am asking because I may expand this to do some other things
>and I haven't really found any references telling me whether or not this is
>efficient.
>#!/usr/bin/perl5 -w
>
>my $address = "foo@bar.com"; #final destination address
>
>open(MAIL, "|/usr/lib/sendmail $address") or die "Could not run sendmail.";
>while (<STDIN>)
>{
> if (/^Subject:/ && /\D(\d{6})\D/)
> {
> print MAIL "Subject: Response for ID\#" . $1;
> print MAIL "\n";
> next;
> }
> else {print MAIL $_;}
>}
>close (MAIL);
>exit;
>
Well, the code could be made a bit terser. Here's how I would do it:
open(MAIL, "| /usr/lib/sendmail $address") || die "Pipe failed: $!\n";
select MAIL;
while (<STDIN>) {
if (/^Subject:/ && /\D(\d{6})(?!\d)/) {
print "Subject: Response for ID#$1\n";
next;
}
print;
}
close(MAIL);
Note:
a) "select MAIL" allows you to use "print" instead of "print MAIL".
b) I altered your regex to allow for six-digit numbers which end the
subject line; your original pattern would miss them.
c) You can interpolate both $1 and \n inside a single double-quoted
string.
d) "print" by itself is equivalent to "print $_" -- an oft-useful
shortcut.
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Thu, 10 Sep 1998 18:24:35 GMT
From: dn5006@my-dejanews.com
Subject: Interactive Perl without stinking braces a la Python
Message-Id: <6t95h2$i0g$1@nnrp1.dejanews.com>
#!/usr/bin/perl -w
use Shell;
$IPERL::l=1; $IPERL::cmd = ""; $IPERL::ind = 0;
sub silent { $IPERL::loud = "" }; sub loud { $IPERL::loud = " " }; &loud;
while ( print("$IPERL::l> " . " "x$IPERL::ind), defined($_=<>) )
{
next if (/^\s*#/);
next if ( (!$IPERL::ind) && (/^\s*$/) );
($_ =~ s/:\s*$/{/) && ($IPERL::ind++);
($IPERL::ind) && (s/^\s*$/}/) && ($IPERL::ind--);
$IPERL::cmd .= $_;
unless ($IPERL::ind) {
$IPERL::res = eval $IPERL::cmd;
print $@ || ($IPERL::loud && $IPERL::res) . "\n";
$IPERL::l++; $IPERL::cmd = "";
}
}
Usage samples:
1> for (1..2):
1> print "Hello $_\n"
1>
Hello 1
Hello 2
2> $a = 4
4
2> while ($a):
2> print "Hello $a\n";
2> $a--;
2>
Hello 4
Hello 3
Hello 2
Hello 1
0
3>:
3> for ($i=3; $i > 0; $i--):
3> print "Hello $i\n"
3>
3>
Hello 3
Hello 2
Hello 1
4>:
4> for ($i=3; $i > 0; $i--)
4> {
4> print "Hello $i\n"
4> }
4>
Hello 3
Hello 2
Hello 1
5> foreach $a (1..2):
5> foreach $b (1..2):
5> print "$a -> $b\n"
5>
5>
1 -> 1
1 -> 2
2 -> 1
2 -> 2
6>
Hints:
1) A colon at the end of a line starts a block of statements.
2) Indentation for a block initiated with a colon is done automatically.
3) An empty line completes a block if any.
4) Everything else is Perl.
Dat Thuc Nguyen
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 10 Sep 1998 19:34:46 +0100
From: Simon Matthews <sam@peritas.com>
To: "Asa C. Martin" <non-spammers_asa.c.martin@boeing.com>
Subject: Re: Looping and grep problem
Message-Id: <35F81BC6.BDC96595@peritas.com>
Asa C. Martin wrote:
>
> Hope this isn't too long. I have a large postscript file that contains
> both a subject and a number that I am trying to parse out. They are
> contained several times in the file, and I just want them once. They
> start by SUBJECT and Number. I am parsing the number fine, but the
> subject is giving me problems. Here's the postscript:
...SNIP
>
> I want just the words in parentheses, from the first f4 (or sometimes,
> f9, f5 etc.) after SUBJECT until the newpath after it. I can only get my
> code to work if I use f4 in the grep; f\d does not work! It is driving
> me crazy. I also know there must be a more efficient way to code the
> routine. Please help!
>
> Here's the code:
>
...SNIP
Try this:
$file = 'ps';
open(PS,"$file") || die "Could not open $file: $!\n";
while (<PS>) {
# Looking for SUBJECT
! $subjFound && /SUBJECT/ && do {
$subjFound = 1;
next;
};
# start looking for words
$subjFound && /f\d/ && do {
$words = 1;
next;
};
# stop looking for words
/^newpath$/ && do {
$words = 0;
next;
};
# found a word
$words && /\((\w+)\)/ && do {
$subject .= ' ' if $subject;
$subject .= $1;
};
}
close(PS);
print "Subject: $subject\n";
Outputs:
Subject: NEW LOADBOARD FOR THE PROCESSOR PRINTED CIRCUIT ASSEMBLY IN THE
RADIO COMMUICATION PANEL
Hope this helps.
SAM
------------------------------
Date: 10 Sep 1998 18:03:25 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Objects & type checking
Message-Id: <6t949d$56p$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Mark Lehrer <mark@satch.markl.com> writes:
:For example, I have an object that could be constructed in several
:different ways. In C++, I would make three different constructors
:that take different arguments. In Perl, it looks like I'll have to
:make a special factory class that has a different-named method for
:each constructor; or else I'll have to look at the @ISA array for each
:argument and do something different based on each possible combination
:of argument types. This doesn't seem like the lazy programmer's way
:to do it.
You're doing it wrong. PLEASE STOP THINKING IN C++. It's hurting you.
Inheritance via @ISA is irrelevant here. You could either make three
methods, called with three different names, or you can write just one
that checks its arguments. Tell me, how can you check the number and
types of arguments in C++? You can't.
--tom
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
--Larry Wall in the perl man page
------------------------------
Date: Thu, 10 Sep 1998 18:29:01 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Objects & type checking
Message-Id: <35F81810.349E7124@bbnplanet.com>
> Perhaps it seems that way to someone who is already familiar with OO
> Perl. It answers a few questions but leaves a lot to be desired (my
> opinion of course).
My fault here, as I assumed someone who programs C++ would probably be
taken with perltoot. I was.
> > hrm. C++ is not Perl. Bad Thinkage.
>
> Perhaps you could be a bit more helpful instead of stating the
> obvious. I am asking for a recommendation on why and what the
> "correct" way to accomplish the same thing might be. Maybe I can
> write a C++ User's introduction to OO Perl after I figure this stuff
> out.
Sorry, you didn't take my point. I try not to apply any programming
language paradigm to another. I made this mistake long ago. Its Bad
Thinkage(tm). A C++ to Perl tutorial would be nice, but I think would
still be off the point. When I go to Germany I have to think in German
and not think in English with translation. Think in Perl.
> That is not what I'm saying; I'm saying that I want to use the same
> method name with different argument types, without having to make an
> if statement to see what type of object each argument is.
Think in Perl. :)
Enjoy.
e.
------------------------------
Date: 10 Sep 1998 14:42:31 -0400
From: Mark Lehrer <mark@satch.markl.com>
Subject: Re: Objects & type checking
Message-Id: <m3yarrhkrs.fsf@satch.markl.com>
Tom Christiansen <tchrist@mox.perl.com> writes:
> [courtesy cc of this posting sent to cited author via email]
unfortunately it was a spam-proof address. 8^)
> In comp.lang.perl.misc, Mark Lehrer <mark@satch.markl.com> writes:
> :Hello. I am new to using perl objects (i've read the simple docs
> :on cpan about a dozen times each and implemented a few classes).
>
> You might also look at the online examples of chapters 11-13 in PCB.
Thanks! I'll take a look.
> :In particular, I
> :am used C++ and having the same function name with several different
> :sets of arguments.
>
> That's your problem: you're thinking in C++. Don't do that. Perl's
> treatment of OO is perfectly sensible--if you think in Perl. For every
> problem that you can't solve by writing Perl exactly as though it were
> Java or C++, there is a native Perl solution that works perfectly well.
I agree, this is my first OO Perl project so I don't know the
differences well, yet. The tutorials haven't done a good job of
explaining them.
I learned that it isn't possible to have two methods of the same class
with the same name; which I'll assume means that I can have only one
constructor per class.
> :In order to do this in Perl, do I have to do something really painful
> :like going through the @ISA array for each argument? Yuck.
>
> What would @ISA have to do with arguments?
How else does a method know what object types were passed to it as
arguments?
> What are you really
> asking here? Are you asking for advice on writing variadic functions?
Yes. I guess it isn't the most important C++ "feature" but it is nice
to have multiple constructors (IMO).
Of course, if this isn't thinking the "perl way" please give me some
enlightenment! (or point me to an "FM" to read)
Thanks,
Mark
------------------------------
Date: 10 Sep 1998 14:17:53 -0400
From: Ala Qumsieh <aqumsieh@tigre.matrox.com>
Subject: Re: pass on value to subroutine call
Message-Id: <x3y67evltm6.fsf@tigre.matrox.com>
"Duncan Cameron" <dcameron@bcs.org.uk> writes:
>
> You're dealing with soft references. Without having tried it, I would
> expect something like
>
> &{$afield(26)} to do what you want.
>
> HTH
I really don't see how your code helps solve Jerom's problem. In fact I
have trouble seeing how it would parse and compile! Please try your
code before posting.
As a possible solution, I suggest you use eval() since it is the
easiest way to get what you want.
thus if $a = "afield(26)"
eval "\&$a";
would do what you want. Note that using eval() in this manner is a bit
risky (read docs). Therefore, if you could store the value to be
passed to the subroutine in a separate scalar, your life would be much
easier. Then, you will be able to do something like:
$subr = "afield";
$value = "26";
&{$subr}($value);
>
> jeroen <jerom@xs4all.nl> wrote in article <35F1A00A.3D5E9D13@xs4all.nl>...
> > Hi there.
> >
> > I could use your help with the following.
> >
> > I'm trying to call subroutines. The subroutine to be called depends on
> > the value in an array. This goes fine, until I need to *pass on a value*
> > when calling a particular subroutine.
> >
> > This is the code that keeps on troubling me:
> >
> > for ($field=1; $field < ($#datatype+1); $field++) {
> > $test = $datatype[$field];
> > &$test;
> > }
> >
> > If the datatype[$field] value is e.g. "timefield", the subroutine call
> > is:
> > &timefield;
> > and this works perfectly fine: the timefield subroutine is executed
> > beautifully.
> >
> > For some types of datatype values I need to pass on a number to the
> > subroutine. To be specific, if the datatype[$field] value is
> > "afield(26)", the call needs to be:
> > &afield(26);
> > where 26 can be any number in the range 0-78.
> >
> > Whatever I have tried so far, it does not execute the sub.
> > Now, I suspect it to be a precedence problem, but I cannot figure out
> > what I should add to have afield(26) be seen as a whole.
> >
> > Is what I'm trying to do possible, and if so, how?
> >
> > Any comments are highly appreciated.
> >
> > Regards,
> > Jerom
> >
Hope this helps,
--
Ala Qumsieh | No .. not Just Another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Thu, 10 Sep 1998 19:14:13 +0100
From: Simon Matthews <sam@peritas.com>
Subject: Re: Perl "mkdir" function
Message-Id: <35F816F5.ED622F64@peritas.com>
Pemail wrote:
>
> Could anyone supply any examples (or url's that provide the source code) of
> perl code that includes the function "mkdir". The reference perl books are
> rather skeletal!
>
> Thanks
>
> Darren
Try:
perldoc File::Path
Hope this helps
SAM
------------------------------
Date: Wed, 09 Sep 1998 14:05:42 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Perl & Java - differences and uses
Message-Id: <35F6C376.BBE60D01@min.net>
George Reese wrote:
>
> In comp.lang.java.programmer John Porter <jdporter@min.net> wrote:
> : George Reese wrote:
> :>
> :> Anything that can be done in Perl can by done in Python more easily.
>
> : That's not "backing it up", that's another dangling allegation.
> : It sounds an awful lot like a religious assertion, which I would
> : not have expected from you, based on statements you have made
> : elsewhere in this thread.
>
> Nonsense. It is actually a really easily testable hypothesis.
O.k., it was a dangling hypothesis, i.e. one provided sans support.
My use of the term "allegation" was loaded, but not inaccurate.
Ergo, not "nonsense".
(And dare I suggest that your language is straying dangerously
close to the ad hominem zone...)
> My
> claim is so sweeping, all you need to do is come up with a single
> situation in which Perl accomplishes a task easier.
True. And I shall relish the achievement. (But not in this post.)
> :> And you can actually read and maintain the Python code.
>
> : No I can't. But I *can* read and maintain Perl code.
> : It's all a matter of what language(s) one already knows.
>
> No, it is not.
Yes, it is.
Well, not *all* a matter, but *largely* a matter....
> First of all, the 'you' above was 'you' in the generic sense.
No, duh.
I am a member of that class, and the statement was
false about me, therefore false in the general.
> One of the measures of a successful language is how easy it is
> for people to pick it up and also for how easy it is for those who
> know the language to read legacy code.
True.
> Perl is notoriously bad on this count.
False.
> To compound its horrid syntax, it also has the single
> nastiest OO paradigm I have ever seen in a programming language.
I don't regard its syntax as horrid; certainly no worse than some
of the other score-odd languages I know.
And nasty is in the eye of the beholder.
I happen to like the design decisions that were made wrt how to
add OO to Perl. Smalltalk it ain't; but Smalltalk ain't gospel,
either.
--
John Porter
------------------------------
Date: Thu, 10 Sep 1998 18:07:37 GMT
From: George Reese <borg@imaginary.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <JzUJ1.688$E9.2428976@ptah.visi.com>
In comp.lang.java.programmer Brent Michalski <perlguy@inlink.com> wrote:
: George Reese wrote:
:>
:> In comp.lang.java.programmer David Cantrell <NukeEmUp@ThePentagon.com> wrote:
:> : George Reese <borg@imaginary.com> enlightened us thusly:
:>
:> :>Perl has no real use. If you have to do scripting or text processing,
:> :>use Python. Otherwise, use Java.
:>
:> : Care to back that up?
:>
:> Well, simple:
:>
:> Anything that can be done in Perl can by done in Python more easily.
:> And you can actually read and maintain the Python code.
: I cannot believe the ignorance on display here!
: This is just like an assembler programmer saying "anything that can be
: done in C can be done in assembler easier, and you can actually read and
: maintain the code."
No, that is not at all the same claim. The claim is that Python is
_technically well-suited_ to the same tasks Perl is AND that Python does
it in a way that is easier to read in maintain.
That is a very different claim than saying that anything you can do in
one you can do in the other.
: If you like Python great, I'm happy for you. It surely doesn't make it
: the end-all do-all language for everyone. So, instead of trolling the
: newsgroup, just accept the fact that some people LOVE to program in Perl
: and others LOVE to program in Python and others LOVE to program in
: Q-BASIC, etc, etc....
The rhetoric of those without any support for their position...
What people LOVE to program in is 100% irrelevant. Language
comparisons are perfectly valid. You choose the one that is best
suited for a given task. You clearly think that one language can be
better suited to a task than another since you made the C/assembly
comparison above.
--
George Reese (borg@imaginary.com) http://www.imaginary.com/~borg
PGP Key: http://www.imaginary.com/servlet/Finger?user=borg&verbose=yes
"Keep Ted Turner and his goddamned Crayolas away from my movie."
-Orson Welles
------------------------------
Date: Wed, 09 Sep 1998 14:13:22 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Perl & Java - differences and uses
Message-Id: <35F6C542.CC098A6D@min.net>
George Reese wrote:
>
> David Cantrell <NukeEmUp@ThePentagon.com> wrote:
> : However, your assertion has been proven wrong. And _why_ is being
> : concise a problem? If you actually look at production perl code, it
> : doesn't appear anything like Obfuscated Perl Contest winners.
>
> Your thesis resist on the premise that fewer keystrokes is better.
> That is false.
Um, the goal was to show how "Perl accomplishes a task easier".
This may or may not be equivalent to "better", in your moral
framework; but I'm having a hard time seeing how
python -c 'import sys; import string; \
print string.atoi(sys.argv[1], 16)' 40
accomplishes its task easier than
perl -e 'print hex shift' 40
> And a beautiful troll looks nothing like an ugly
> troll -- but they are still both trolls.
As Mr. Reese's recent posts in comp.lang.perl.misc neatly demonstrate.
--
John Porter
------------------------------
Date: Thu, 10 Sep 1998 18:33:42 GMT
From: George Reese <borg@imaginary.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <aYUJ1.696$E9.2428976@ptah.visi.com>
In comp.lang.java.programmer John Porter <jdporter@min.net> wrote:
: George Reese wrote:
:>
:> In comp.lang.java.programmer John Porter <jdporter@min.net> wrote:
:> : George Reese wrote:
:> :>
:> :> Anything that can be done in Perl can by done in Python more easily.
:>
:> : That's not "backing it up", that's another dangling allegation.
:> : It sounds an awful lot like a religious assertion, which I would
:> : not have expected from you, based on statements you have made
:> : elsewhere in this thread.
:>
:> Nonsense. It is actually a really easily testable hypothesis.
: O.k., it was a dangling hypothesis, i.e. one provided sans support.
It is not one that requires support. It is one that requires
counterexamples. It is the nature of the hypothesis in question. The
only thing that matters is whether it is testable. And it is easily
testible.
: My use of the term "allegation" was loaded, but not inaccurate.
You said "religious assertion", not "allegation". And that was not
inaccurate, it was nonsense.
: Ergo, not "nonsense".
Yes, nonsense. Religious assertions and testable hypothesis are polar
opposites.
: (And dare I suggest that your language is straying dangerously
: close to the ad hominem zone...)
I have made no claims about you; I have not called you any names. You
are being way oversensitive (here I am making a claim about you, but a
claim supported by your behaviour). If you cannot handle a frank
assessment of the weakness of your statements, you should not be
engaging in debate.
:> My
:> claim is so sweeping, all you need to do is come up with a single
:> situation in which Perl accomplishes a task easier.
: True. And I shall relish the achievement. (But not in this post.)
I await this. I am certainly open to the possibility something out
there exists for which Perl is better suited than Python. But I think
it should be a hollow victory unless you can go beyond my mandate and
show that Perl is significantly better suited to the task in
question. Furthermore, in order for Perl to actually be 'a better
language' than Python, you would have to show that this (or any other
potential strengths) override the tremendous downside of the
design inconsistency, poor maintainability, shoddy object model of
Perl. Since that is so difficult to prove, I have provided Perl
lovers with an easy target: just prove Perl is better suited for one
task--any task.
:> :> And you can actually read and maintain the Python code.
:>
:> : No I can't. But I *can* read and maintain Perl code.
:> : It's all a matter of what language(s) one already knows.
:>
:> No, it is not.
: Yes, it is.
: Well, not *all* a matter, but *largely* a matter....
Not in the least. The maintainability of code is how easy it is to
to extend, keep up to date, and fix bugs in for people who are nto the
original authors. While knowing a language is a big criteria for
being able to maintain something, it does not cut it at all. That is
why the OO paradigm is so important. It helps organize code into
logical components with well-defined interfaces. And that is where
Perl is incredibly weak. Not only was an OO paradigm an afterthought,
it was a horribly hacked together afterthough.
Then there is the ability to read code. Perl is the only language I
know of where an expert has to concentrate to read the code of another
expert. Maintainence is rarely the realm of the exprts, but instead
the place people put newbie coders. God forbid you ask a newbie to
maintain Perl code.
:> First of all, the 'you' above was 'you' in the generic sense.
: No, duh.
: I am a member of that class, and the statement was
: false about me, therefore false in the general.
You are misunderstanding the role of generalization. The truth value of
that proposition is completely independent of whether it happens to be
true of you in particular.
:> One of the measures of a successful language is how easy it is
:> for people to pick it up and also for how easy it is for those who
:> know the language to read legacy code.
: True.
:> Perl is notoriously bad on this count.
: False.
OK, you disagree on this. I think, however, one look at any perl code
speaks for itself to the general populace.
:> To compound its horrid syntax, it also has the single
:> nastiest OO paradigm I have ever seen in a programming language.
: I don't regard its syntax as horrid; certainly no worse than some
: of the other score-odd languages I know.
You know worse? I am sorry if I don't find that defense of Perl.
: And nasty is in the eye of the beholder.
: I happen to like the design decisions that were made wrt how to
: add OO to Perl. Smalltalk it ain't; but Smalltalk ain't gospel,
: either.
"Beauty is in the eye of the beholder" is the mantra of ugly people.
Most people will point to super models when asked "who in this line up
is beautiful?" Not everyone, but a good portion.
The same applies to ugliness of code. People defending nasty languages
often claim that "nasty is in the eye of the beholder". But the proof
is in the pudding. Most people will find python code much more
readable than Perl code for most applications. Not everyone, but a
good portion.
--
George Reese (borg@imaginary.com) http://www.imaginary.com/~borg
PGP Key: http://www.imaginary.com/servlet/Finger?user=borg&verbose=yes
"Keep Ted Turner and his goddamned Crayolas away from my movie."
-Orson Welles
------------------------------
Date: Thu, 10 Sep 1998 13:52:39 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: Perl/Html - mixing text and graphics
Message-Id: <6t93l7$eq6$1@earth.superlink.net>
"Antti Boman" <antti.boman***NOSP@M***helsinki.fi> writes:
>> print("<img src="/images/bitmaps/%s.gif" width=400 height=250>",$AREA);
>How about...
> print "<img src="/images/bitmaps/".$AREA".gif" width=400 height=250>";
>...?
How about it?
orpheus:~$ perl -e 'print "<img src="/images/bitmaps/".$AREA".gif" width=400 height=250>"'
Illegal division by zero at -e line 1.
David Black
dblack@orpheus.shu.edu
------------------------------
Date: Thu, 10 Sep 1998 19:09:07 +0100
From: Simon Matthews <sam@peritas.com>
Subject: Re: replacing text in a string
Message-Id: <35F815C3.EAFBE700@peritas.com>
Kevin Reid wrote:
>
> Mark Lehrer <mark@satch.markl.com> wrote:
>
> > What is the best way to substitute a few characters in the middle of
> > a string? I am using the slowest possible method:
> >
>
> I first thought of this:
>
> $foo = '123abc789';
>
> $newstr = $foo;
> substr($newstr, 0, 3) = '456';
>
> I also considered this, but thought it would be slower:
>
> $foo = '123abc789';
> $newstr = $foo;
> $newstr =~ s/^.{3}/456/;
>
>
> Benchmark: timing 200000 iterations of his, mine, re...
> his: 4 secs ( 3.98 usr 0.00 sys = 3.98 cpu)
> mine: 4 secs ( 5.07 usr 0.00 sys = 5.07 cpu)
> re: 3 secs ( 3.62 usr 0.00 sys = 3.62 cpu)
>
> It looks like the regular expression is the fastest.
Not so. The code above is not all doing the same thing. The original
produces
a newstr = '123456789'. Both of your versions produce a string of
456abc789. In order to replace in the middle of the string I think youd
have to store a back reference to the first three characters. This is
much slower (see details below (sam1)). Even your first go fixed to
insert the characters in the correct place is slower than the original
(marginaly), which surprised me. I would use your first version, I looks
much neater than 'his'. I added sam3 just to see if it was quicker if
you were just matching a string. It would appear that even this is
slower than the substr = approach. But again this is marginal.
Benchmark: timing 1250000 iterations of his, mine, re, sam1, sam2,
sam3...
his: 17 secs (17.98 usr 0.00 sys = 17.98 cpu)
mine: 18 secs (18.41 usr 0.00 sys = 18.41 cpu)
re: 18 secs (17.79 usr 0.00 sys = 17.79 cpu)
sam1: 64 secs (64.53 usr 0.00 sys = 64.53 cpu)
sam2: 19 secs (18.40 usr 0.00 sys = 18.40 cpu)
sam3: 19 secs (20.09 usr 0.00 sys = 20.09 cpu)
Modified script below.
use Benchmark;
my $times = shift @ARGV || 1;
timethese($times, {
his => sub {
$foo="123abc789";
$newstr=substr($foo,0,3) . "456" . substr($foo,6);
print "his $newstr\n" if $times == 1;
},
mine => sub {
$foo = '123abc789';
$newstr = $foo;
substr($newstr, 0, 3) = '456';
print "mine $newstr\n" if $times == 1;
},
re => sub {
$foo = '123abc789';
$newstr = $foo;
$newstr =~ s/^.{3}/456/;
print "re $newstr\n" if $times == 1;
},
sam1 => sub {
$foo = '123abc789';
$newstr = $foo;
$newstr =~ s/^(.{3}).{3}/${1}456/;
print "sam1 $newstr\n" if $times == 1;
},
sam2 => sub {
$foo = '123abc789';
$newstr = $foo;
substr($newstr, 3, 3) = '456';
print "sam2 $newstr\n" if $times == 1;
},
sam3 => sub {
$foo = '123abc789';
$newstr = $foo;
$newstr =~ s/abc/456/;
print "sam3 $newstr\n" if $times == 1;
}
});
Hope this helps.
SAM
------------------------------
Date: Thu, 10 Sep 1998 11:05:02 -0700
From: Jian Zhang <jian@cisco.com>
Subject: Tokenizer in Perl...
Message-Id: <35F814CE.78E233AD@cisco.com>
Hi,
I am new to Perl and working on a simple parser. I'm looking for a way
doing tokenization in Perl. For example, given a string:
module my_module(33: 3){
The perl program should parse the string into an array:
@string_array = (" ",
"module",
" ",
"my_module",
"(",
"33",
":",
" ",
"3",
")",
"{");
Please note that I also need all white-spaces preserved and accurately
parsed.
If someone could give some hint or even an example (if it's not too
complicated), it would be greatly appreciated.
Thanks in advance.
Jian Zhang
San Jose, CA
------------------------------
Date: 10 Sep 1998 18:24:54 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Tokenizer in Perl...
Message-Id: <6t95hm$726@news-central.tiac.net>
In article <35F814CE.78E233AD@cisco.com>, Jian Zhang <jian@cisco.com> wrote:
>Hi,
>
>I am new to Perl and working on a simple parser. I'm looking for a way
>doing tokenization in Perl. For example, given a string:
>
> module my_module(33: 3){
>
>The perl program should parse the string into an array:
>
> @string_array = (" ",
> "module",
> " ",
> "my_module",
> "(",
> "33",
> ":",
> " ",
> "3",
> ")",
> "{");
There are modules on CPAN which may do what you want quite well, but if
you want a simple one liner as a quick & dirty way to do it here's what I
just did in the debugger:
DB<1> $s = 'module my_module(33: 3){'
DB<2> @string_array = $s =~ /(\w+|\s+|.)/g
DB<3> X string_array
@string_array = (
0 'module'
1 ' '
2 'my_module'
3 '('
4 33
5 ':'
6 ' '
7 3
8 ')'
9 '{'
)
I just notices that I forgot to cut the initial white space, but if you
put the leading soaces in the string in step one you'll get the result you
wanted...
CPAN is the comprehensive perl archive network, one way of getting to it
is via http://www.perl.com/CPAN/
You can play with the debugger using the command
perl -de 1
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 10 Sep 1998 18:26:57 GMT
From: harold@foo.bar ()
Subject: Re: vt520 emulation.
Message-Id: <6t95lh$p0b$1@newton2.pacific.net.sg>
Find a termcap or terminfo entry for vt520 and decompile it .
Y W Wong (ywwong_hk@hotmail.com) wrote:
1 : I need to know the keyboard mapping / decode map of the vt520 such that
2 : the script
3 : can send and receive the correct extended characters for the function
4 : keys, such as
5 : F1- F10, shift-F6 etc.
------------------------------
Date: Thu, 10 Sep 1998 11:39:27 -0700
From: Mark Williams <markw@nc.com>
Subject: win32::internet question
Message-Id: <35F81CDE.CB12D687@nc.com>
I've been using the win32::internet package by
Aldo Calpini. It works great, but there seems to be
a feature that was ommitted.
I can't see a way, looking at the syntax of the
HTTP function, to post data to a secure form.
I looks like the HTTP function restricts you to posting to
a non-secure page, just by the syntax of the function.
Any ideas? Thanks in advance,
-mark
--
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Mark Williams phone:650.631.5204
Systems Administrator pager:650.570.8713
Network Computer Inc. email:markw@nc.com
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
------------------------------
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 3682
**************************************