[10550] in Perl-Users-Digest
Perl-Users Digest, Issue: 4142 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 3 17:07:33 1998
Date: Tue, 3 Nov 98 14:00:21 -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, 3 Nov 1998 Volume: 8 Number: 4142
Today's topics:
A nifty regex trick (Sean McAfee)
Re: A nifty regex trick <uri@fastengines.com>
Re: A nifty regex trick (Ilya Zakharevich)
Re: A nifty regex trick (Tad McClellan)
Array Ref Question <b-i-lla@tqs.antispam.com>
Re: Check this out... (Larry Rosler)
Re: Check this out... (Andre L.)
Re: find and replace (clay irving)
Re: find and replace (Tad McClellan)
Re: find and replace (Joergen W. Lang)
flushing buffer to STDOUT rabisteve@my-dejanews.com
Re: HELP! I need a perl enviroment for Win 95 <gellyfish@btinternet.com>
Re: illegitimate data types ? (Patrick Timmins)
RE: Not to start a language war but.. <klm@cnri.reston.va.us>
RE: Not to start a language war but.. <klm@cnri.reston.va.us>
Re: Not to start a language war but.. <garry@sage.att.com>
Re: PERL is TOO flexible (Larry Rosler)
Re: PERL is TOO flexible (Larry Wall)
Re: PERL is TOO flexible (Andre L.)
Re: PERL is TOO flexible (Andrew M. Langmead)
perl modules (J Holden)
PROBLEMS! Installing Date:Manip <imran.hussain@csfb.com>
Re: PROBLEMS! Installing Date:Manip (Sean McAfee)
Re: Reading multiple lines <webmaster@topproducer.com>
Re: Reading multiple lines (Tad McClellan)
Re: Reading multiple lines (Joergen W. Lang)
Re: replicating `more` <gellyfish@btinternet.com>
Re: Shell built-in commands in a perl script? <kprice@cardinal.co.nz>
single quotes in filename anthonyr1234@my-dejanews.com
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Nov 1998 20:00:56 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: A nifty regex trick
Message-Id: <YhJ%1.4914$fS.16023839@news.itd.umich.edu>
In the past, when I wanted to match a string against a number of
alternatives, I would do something like this:
@options = qw/ foo bar baz bletch /;
$options = join "|", @options;
while (<>) {
print $1 if /($options)/o;
}
Recently I realized that since regex patterns are interpolated in the same
way that strings are, one could do this instead:
@options = qw/ foo bar baz bletch /;
$" = "|"; # wrap in block and make local if necessary
while (<>) {
print $1 if /(@options)/o;
}
I don't believe I've seen this idiom anywhere before. Just thought
I'd share!
--
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: 03 Nov 1998 15:34:16 -0500
From: Uri Guttman <uri@fastengines.com>
Subject: Re: A nifty regex trick
Message-Id: <sar67cwv7lj.fsf@camel.fastserv.com>
>>>>> "SM" == Sean McAfee <mcafee@waits.facilities.med.umich.edu> writes:
SM> Recently I realized that since regex patterns are interpolated in
SM> the same way that strings are, one could do this instead:
SM> @options = qw/ foo bar baz bletch /;
SM> $" = "|"; # wrap in block and make local if necessary
SM> while (<>) {
SM> print $1 if /(@options)/o;
SM> }
a couple of points:
first, remember to reset $" back to space afterwards. this is best done
by using local in a block to set it. upon exit of the block it will get
its last value.
secondly, the | in regexes can be slow. in many cases it would be faster
to use a || list of separate regexes generated by evaling a string or
qr//.
if your tokens are fixed strings, index can be faster than a regex (i
have read counter claims depending on the internal way perl optimizes
things.)
the cookbook has some ideas on how to make closures do this as well.
so your idiom is nice but not as effective as you would think.
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 3 Nov 1998 20:45:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: A nifty regex trick
Message-Id: <71nq1o$b7p$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@fastengines.com>],
who wrote in article <sar67cwv7lj.fsf@camel.fastserv.com>:
> if your tokens are fixed strings, index can be faster than a regex (i
> have read counter claims depending on the internal way perl optimizes
> things.)
It was just a bug in the PP optimizer for index() - it was looking at
a wrong kid, so did not recognize situations it should have been. I
think Larry sent a patch for it in summer, it probably did it into 5.005_*.
Ilya
------------------------------
Date: Tue, 3 Nov 1998 16:41:09 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: A nifty regex trick
Message-Id: <5q0o17.83a.ln@flash.net>
Uri Guttman (uri@fastengines.com) wrote:
: >>>>> "SM" == Sean McAfee <mcafee@waits.facilities.med.umich.edu> writes:
: SM> Recently I realized that since regex patterns are interpolated in
: SM> the same way that strings are, one could do this instead:
: SM> @options = qw/ foo bar baz bletch /;
: SM> $" = "|"; # wrap in block and make local if necessary
: SM> while (<>) {
: SM> print $1 if /(@options)/o;
: SM> }
: a couple of points:
: first, remember to reset $" back to space afterwards. this is best done
: by using local in a block to set it. upon exit of the block it will get
: its last value.
: secondly, the | in regexes can be slow. in many cases it would be faster
: to use a || list of separate regexes generated by evaling a string or
: qr//.
thirdly, through in a 'reverse sort':
@options = reverse sort qw/ foo bar baz bletch /;
or "leftmost first" may bite you:
----------------------------
#!/usr/bin/perl -w
#@options = reverse sort qw/ foo bar barbie /;
@options = qw/ foo bar barbie /;
$_ = 'barbie';
$" = '|';
print "$1\n" if /(@options)/o;
----------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 03 Nov 1998 12:57:56 -0800
From: Bill Adams <b-i-lla@tqs.antispam.com>
Subject: Array Ref Question
Message-Id: <363F6E54.A5240360@tqs.antispam.com>
Bug or feature?
Can someone explain what is going on in the following script,
specifically, why the last version actually assigns the value to the
array element? Was this an intended "Feature"? And is the explanation
of this in the man page and did I completely miss it?
This program produces the same output for perl 5.004_04 and 5.005_00.
Thanks.
--Bill Adams
/home/thor/bill/src=>./perlbug.pl
1 Array Has: 1
2 Array Has: 1
3 Array Has: 3
/home/thor/bill/src=>cat perlbug.pl
#!/usr/bin/perl -w
use strict;
my $array_ref = +['1'];
my $step = 1;
print $step++, " Array Has: ", join('|', @$array_ref), "\n";
#This does not change the value in the array:
foreach (@$array_ref) {
my $value = $_;
$value = 2}
print $step++, " Array Has: ", join('|', @$array_ref), "\n";
#This does change the value.
foreach my $value (@$array_ref) {
$value = '3'}
print $step++, " Array Has: ", join('|', @$array_ref), "\n";
/home/thor/bill/src=>
------------------------------
Date: Tue, 3 Nov 1998 11:59:26 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Check this out...
Message-Id: <MPG.10a90076f432d3ac989861@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <71nk9g$bh112@mercury.adc.com> on 3 Nov 1998 19:07:28 GMT,
Brand Hilton <bhilton@tsg.adc.com> says...
...
> $var =~ s/ /+/g;
>
> This is a really, really, really basic question.
And your really, really, really basic answer works. But when there is
another answer that is perhaps an order of magnitude faster, that would
be better to disseminate, as Craig Berry did.
Whenever the question is "How can I replace all characters in a set with
characters from another set, or delete all characters in a set?", the
'tr' solution should come to mind. Benchmark it and see!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 03 Nov 1998 15:49:16 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Check this out...
Message-Id: <alecler-0311981549160001@dialup-733.hip.cam.org>
In article <363F41D5.18FA2C63@nova-creations.com>,
anthony@nova-creations.com wrote:
> Hi!
>
> Does anyone know how I can reformat an in coming variable by replacing
> blank spaces with + signs?
>
> example: (test1 test2 test3) would become (test1+test2+test3)
>
> Thanks!
Well, check out the documentation, dude.
Andre
------------------------------
Date: 3 Nov 1998 15:25:32 -0500
From: clay@panix.com (clay irving)
Subject: Re: find and replace
Message-Id: <71nors$dm5@panix.com>
In <363EE26B.15642836@1185design.com> mikej <mikej@1185design.com> writes:
>Hi everyone,
>Im trying to open an html file and replace parts of it. I basically open
>the file and try to do a substitute command on keywords already in the
>file, which should get replaced. Say I want to change where it says
><!--replace me--> to <!--it worked--> in an html page. I call this
>subroutine:
> sub replace_text {
> open (MYFILEHANDLE, ">>files/index.html");
> while ($content = <MYFILEHANDLE> {
> $content =~ s/<!--replace me-->/<!--it worked-->/i;
> }
> close MYFILEHANDLE;
> }
>It is supposed to go through my html file and replace where it says
>"<!--replace me-->" with "<!--it worked-->", but it doesn't do anything.
>
>Anyone know what is wrong with it? Any examples of find and replace
>scripts that are easy to understand would be a good help too. Thanks for
>your help.
>
A few questions for thought:
1. Where did you write the result of the substitution?
2. Did your open succeed?
3. Did you use perl -w
--
Clay Irving
clay@panix.com
------------------------------
Date: Tue, 3 Nov 1998 15:01:36 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: find and replace
Message-Id: <gvqn17.bk9.ln@flash.net>
mikej (mikej@1185design.com) wrote:
: Im trying to open an html file and replace parts of it.
: sub replace_text {
: open (MYFILEHANDLE, ">>files/index.html");
^^
^^ open file for _writing_ ...
: while ($content = <MYFILEHANDLE> {
^^^^^^^^^^^^^^
^^^^^^^^^^^^^^ ... and then read from it!
: Anyone know what is wrong with it?
It was not run with warnings enabled, that's what's wrong.
You should enable warnings on every Perl script.
Really. Every one.
It would have pointed out the problem immediately...
: Any examples of find and replace
: scripts that are easy to understand would be a good help too. Thanks for
: your help.
Perl FAQ, part 5:
"How do I change one line in a file/
delete a line in a file/
insert a line in the middle of a file/
append to the beginning of a file?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 3 Nov 1998 22:41:55 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: find and replace
Message-Id: <1dhxrsb.2ie69w1lb8vbfN@host034-210.seicom.net>
mikej <mikej@1185design.com> wrote:
> Hi everyone,
>
> Im trying to open an html file and replace parts of it. I basically open
> the file and try to do a substitute command on keywords already in the
> file, which should get replaced. Say I want to change where it says
> <!--replace me--> to <!--it worked--> in an html page. I call this
> subroutine:
Mind if I try ?
> sub replace_text {
>
> open (MYFILEHANDLE, ">>files/index.html");
Open files/index.html in "append-write" - mode. New stuff gets added to
the end of the file.
You need to read your info from the file first. Otherwise $content will
not contain very much you could use.
You also want to _always_ check the return value of an "open".
> while ($content = <MYFILEHANDLE> {
> $content =~ s/<!--replace me-->/<!--it worked-->/i;
> }
You have to print your manipulated data back to the file to see any
changes.
> close MYFILEHANDLE;
>
> }
> It is supposed to go through my html file and replace where it says
> "<!--replace me-->" with "<!--it worked-->", but it doesn't do anything.
>
So you probably want something like the following:
#!/usr/bin/perl -w
#===========================#
# 1. Using a temporary file.#
#===========================#
$old = "oldfile"; # store names away for later
$new = "newfile";
sub replace_using_tempfile {
open OLD, "$old" or die "Can't open $old for read. Reason: $!";
# read mode
open NEW, ">$new" or die "Can't open $new for write. Reason: $!";
# write mode
while ($content = <OLD>) {
$content =~ s/<!--replace me-->/<!--it worked-->/;
# do the change
print NEW $content;
}
close OLD;
close NEW;
unlink $old;
# get rid of the old file
rename $new, $old;
}
#====================#
# 2. Do it "inplace" #
#====================#
sub replace_inplace {
open MYFILEHANDLE, "+<files/index.html" or die "Can't open file:$!";
# open for read and write.
@file = <MYFILEHANDLE>;
# read in file
foreach $content (@file) {
s/<!--replace me-->/<!--it worked-->/;
}
# edit
seek (MYFILEHANDLE, 0, 0);
# "rewind" to beginnng of file
print MYFILEHANDLE @file;
# write back to file
close MYFILEHANDLE;
# done
}
__END__
hope this helps, HANW,
Joergen
--
To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
"Everything is possible - even sometimes the impossible"
HOELDERLIN EXPRESS - "Touch the void"
------------------------------
Date: Tue, 03 Nov 1998 21:41:01 GMT
From: rabisteve@my-dejanews.com
Subject: flushing buffer to STDOUT
Message-Id: <71nt9e$bof$1@nnrp1.dejanews.com>
Hello News people,
I am constructing a script which communicates via tcpip
I am not Mr. Scripter so you can flame me now.
At any rate the other computer which I am communicating with is sending a
response. I know this because I see it in its log. Additionally, when the
other computer (which happens to be running OpenVMS) cuts communications I
see the contents printed out on the Standard Output
I understand that this may be a problem with flushing the buffer the script
below (whihc I downloaded from somewhere) seems to do this:
select(S); $| = 1; select(STDOUT);
The massage from the Open VMS does not have line endings or anything
conveinent like that.
I would really appreciate and give a blessing to whomever tells me where to
stick another one of these flushers so that I can see the text as it is sent
from Mr OpenVMS
The more specific the information the more helpful it will be. I often take
stupid pills. This puts me on the level of the people I must assist.
BTW - the Perl script is runmmimg perl 5004 on an an Alpha running Diigtal
unix 4b (I believe)
Thanks,
Steve
#!/usr/bin/perl
#binds the port
($them,$port) = @ARGV;
$port = 2345 unless $port;
$them = 'localhost' unless $them;
$AF_INET = 2;
$SOCK_STREAM = 1;
$SIG{'INT'} = 'dokill';
sub dokill {
kill 9,$child if $child;
}
$sockaddr = 'S n a4 x8';
chop($hostname = `hostname`);
($name,$aliases,$proto) = getprotobyname('tcp');
($name,$aliases,$port) = getservbyname($port,'tcp')
unless $port =~ /^\d+$/;;
($name,$aliases,$type,$len,$thisaddr) =
gethostbyname($hostname);
($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
# Make the socket filehandle.
if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
print "socket ok\n";
}
else {
die $!;
}
# Give the socket an address.
if (bind(S, $this)) {
print "bind ok\n";
}
else {
die $!;
}
# Call up the server.
if (connect(S,$that)) {
print "connect ok\n";
}
else {
die $!;
}
# Set socket to be command buffered.
select(S); $| = 1; select(STDOUT);
# Avoid deadlock by forking.
if($child = fork) {
while (<STDIN>) {
print S;
}
sleep 3;
do dokill();
}
else {
while(<S>) {
print;
}
}
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 3 Nov 1998 20:34:28 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: HELP! I need a perl enviroment for Win 95
Message-Id: <71npck$q5$1@gellyfish.btinternet.com>
On Mon, 02 Nov 1998 17:56:49 -0800 Cornuts <cornuts@mrfoda.com> wrote:
> Does anyone know where I can download software to program in perl
> besides CPAN and Active state. I have searched around and found those
> two sites as the only ones who actually distribute perl software
> (enviroments) I have downloaded from both of those sites and found
> "uncleanable" viruses in each.
I would trade in the virus checker for something better.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Tue, 03 Nov 1998 20:31:26 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: illegitimate data types ?
Message-Id: <71np6v$5ri$1@nnrp1.dejanews.com>
In article <71nef7$ls0$1@nnrp1.dejanews.com>,
mgrabens@my-dejanews.com wrote:
> In the following code snigglet, does this create an illegitimate data type?
> $myhash{key1} = 'Person';
> $myhash{key1}{fname} = 'Mike';
> $myhash{key1}{lname} = 'Grabenstein';
> $myhash{key2} = 'Class';
> ... etc ...
Bastard data types? Never! Both parents are listed on the birth
certificate under the surname 'perldoc': (Mrs. perlref perldoc and
Mr. perldsc perldoc).
Patrick Timmins
$monger{Omaha}[0]
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 3 Nov 1998 15:30:37 -0500
From: Ken Manheimer <klm@cnri.reston.va.us>
To: Blake Winton <BlakeW@pcdocs.com>
Subject: RE: Not to start a language war but..
Message-Id: <Pine.GSO.3.96.981103143120.3872d-100000@glyph.cnri.reston.va.us>
On Tue, 3 Nov 1998, Blake Winton wrote:
> try:
> article = open(filename, 'r')
> except IOError, oops:
> Warn("Can't open article file %s because %s" %
> (filename, oops.strerror))
> [...]
> So how is this example different?
>
> On Monday, November 02, 1998 9:04 PM, Zenin [SMTP:zenin@bawdycaste.org]
> wrote:
>
> > handler is very much like a normal OO exception handler (eg, a Java
> > catch{} or Python except block), with the *extra* ability to
> > *return* from the exception handler to the location where warn() or
> > die() was called. This is why it is handled by a %SIG handler, as
>
> Hmmm... This might be how it's different...
> Since the exception has access to the call stack, it could
> conceivably continue on from the point the exception was
> raised, but it seems "difficult"...
>
> To the other Pythoneers:
> How hard would it be? Would it be any easier to add something
> to the language (like "continue", but for exceptions)?
> Is this already on the drawing board for Python 2.0?
> Should it be?
Actually, it's a good idea, and not uncommon for python programs to do
just that. From the python ref manual: "If no expressions are present,
[a bare] "raise" re-raises the last expression that was raised in the
current scope." So you can just use a bare raise from within an
exception to do what you're seeking.
The bare raise for reraising the current exception is a recent shortcut,
by the way. The alternative - providing a traceback as the optional
third argument to raise - has been around for a while. When provided,
it specifies the stack frame that the exception will consider to be the
site of occurence. (This sort of thing turns out to be particularly
handy for what i'd call "executive" code, programs that are responsible
for managing the evaluation of other code.) See the python raise
statement ref manual page (http://www.python.org/doc/ref/raise.html)
for more details.
I might as well take this opportunity to describe what i see as the crux
of the difference, regarding exceptions, between perl and python. The
issue is not whether the languages are able to handle out-of-band
exceptions - via try...except in python, and, if i understand correctly,
eval{die/croak} in perl. Rather, the difference is in how demanding the
languages are in requiring the programmer to anticipate and handle the
exceptional situations.
>From what i've seen here, at least w.r.t. file io, perl takes a fairly
lenient approach to exception conditions, requiring the programmer to be
proactive and check for them. Kinda like a lot of C routines. Python,
on the other hand, is more demanding - if you don't anticipate an
exception, then you're gonna get disrupted.
There is a critical advantage in this strictness. Kablooie, unexpected
conditions make themselves known, right when they occur - with a
traceback indicating all the intervening stack frames, to boot. This is
as opposed to having the effect of the aberration show up somewhere,
possibly far, down the road, when the screwed up state finally
collapses. This displacement of cause and effect will almost always
make debugging harder, because the site of the underlying problem is
passed, possibly long gone. I think the strict approach is better in
most circumstances - it puts the burden on the programmer to do it
right, with clear and immediate consequences when they don't.
There are some circumstances where you do want to ignore all exceptions
- maybe a quick, desperate maneuver you want the code to try, but you
know will almost never work, "and who cares anyway"... Then you can use
a bare "except:" - with the benefit of being very damn explicit about
your cavalier attitude. This way others using your code (what, you've
never had grotesque hacks that turned out to be useful, and spread?) can
see that's what you're doing, and fix it or not, as they choose. No
surprises. Which is one of the things good programming is about.
Obviously, i'm in favor of this explicit, notice-where-and-when-it-
bites-you approach.
Ken Manheimer klm@python.org 703 620-8990 x268
(orporation for National Research |nitiatives
# If you appreciate Python, consider joining the PSA! #
# <http://www.python.org/psa/>. #
------------------------------
Date: Tue, 3 Nov 1998 16:24:27 -0500
From: Ken Manheimer <klm@cnri.reston.va.us>
To: Blake Winton <BlakeW@pcdocs.com>
Subject: RE: Not to start a language war but..
Message-Id: <Pine.GSO.3.96.981103160616.3872e-100000@glyph.cnri.reston.va.us>
Doh. On rereading the original question i see i was answering something
different. Sorry about that!
> On Tue, 3 Nov 1998, Blake Winton wrote:
> try:
> foo()
> bar()
> baz()
> except ProgressException, detail:
> print "Operation %s %d%% done" % (detail.op, detail.percent)
> continue # Or whatever will continue executing the try block...
Instead, i talked about something that provides the ability to reraise
an exception, which is decidedly not continuing to process the try
block:-). Sheesh.
There are other ways to do what you want, of course, using the ability
to catch the exception in the first place. Eg:
done = 0
while done != 1:
try:
foo()
done = 1
except ProgressException, detail:
print "Operation %s %d%% done" % (detail.op, detail.percent)
Of course, foo() needs to be built to be resumable, but there's a lot of
ways (more than one, certainly:-) to do that. And you could encapsulate
this progress loop in a routine which takes other routines as its
argument, to make it easy to apply to a bunch of things:
shepherd(foo)
shepherd(bar, args...)
shepherd(baz, etc)
What you're seeking is lots harder - a resumable stack. Instead of
getting tracebacks, which indicate where in the stack the exception
occurred, the except clause would get a full fledged continuation, which
captures the resumable state of the stack. There's been some talk about
doing this - it may well be useful for things like mobile agents, like
the knowbots that we're working on at cnri (http://www.cnri.reston.va.us)
but so far it has not been done - and from what i hear, and can only
imagine, it would not be a trivial thing to do.
Ken Manheimer klm@python.org 703 620-8990 x268
(orporation for National Research |nitiatives
# If you appreciate Python, consider joining the PSA! #
# <http://www.python.org/psa/>. #
------------------------------
Date: Tue, 03 Nov 1998 16:22:42 -0500
From: "Garrett G. Hodgson" <garry@sage.att.com>
Subject: Re: Not to start a language war but..
Message-Id: <363F7422.61FDB6BE@sage.att.com>
Anita M Wilcox wrote:
>
> >
> >>: * its cleaner and simpler.
> >
> >> Perl is complex, it's a feature.
> >
> >It sure is. Unfortunately, Perl code is complex as well.
> >
> Can we say "job security"? Seriously, whether you prefer one
> language over another, it is irrelevant as far as your career
> goes if no one will hire you to work with it. I'm a consultant
> and have to have a fairly broad repertoire of skills, and, as
> such, have to try to cram in learning as much as possible. In
> terms of the Python/Perl debate, Perl wins hands-down.
sounds like VB or cobol is a better bet.
particularly cobol, at least until 1/1/00.
--
Garry Hodgson and when they offer
garry@sage.att.com golden apples
Software Innovation Services are you sure you'll refuse?
AT&T Labs heaven help the fool.
------------------------------
Date: Tue, 3 Nov 1998 12:08:48 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: PERL is TOO flexible
Message-Id: <MPG.10a902a76156ba85989862@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <alecler-0311981530250001@dialup-733.hip.cam.org> on Tue, 03
Nov 1998 15:30:25 -0500, Andre L. <alecler@cam.org> says...
> In article <3638676E.F980FC4A@harris.com>, "PERL ROCKS!"
> <emills@harris.com> wrote:
...
> > print "stuff\n";
> > print ("stuff\n");
> >
> > What does this add?
>
> Well, the second one causes a compiler warning if you use -w, which you should.
No, it doesn't; and yes, you should; and *you* should try it before
posting.
You may have been thinking of the situation where the first element of a
list of two or more arguments is parenthesized for some reason.
print ($foo ? "stuff\n" : "foobar\n"), "more stuff\n";
This problem is fixed by using parentheses around the entire list, or by
prefixing unary plus to the parenthesized argument.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Nov 1998 12:37:41 -0800
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: PERL is TOO flexible
Message-Id: <71npil$lo4@kiev.wall.org>
In article <3638676E.F980FC4A@harris.com>,
PERL ROCKS! <emills@harris.com> wrote:
> It seems to me, Computer Scientist that I am, that a language developer
> would have as an objective, a minimal grammar.
We already have a zillion miminalistic languages. CS departments are
full of 'em. Sometimes you have to go around stomping the little
beggars just to keep their population in check.
But I'm not really a Computer Scientist. I'm only half a Computer
Scientist. I'm also half a Linguist. The design of Perl reflects
this. For a list of ways in which Perl was designed to work like
a natural language, see
http://kiev.wall.org/~larry/natural.html
> Additional complexity adds nothing to the language's capabilities or
> power;
That depends entirely on how you define power. Sure, any CS language
is Turing complete in an abstract sense. But in a very real sense,
*no* computer language is Turing complete, because no computer language
runs on a machine with an infinite tape. Real programs have many
limitations imposed on them. Historically, programs have been limited
in how big they were allowed to get, or in how slow they were allowed
to run. Nowadays computers are faster and bigger, so the limitations
on our programs have more to do with the impedence mismatch between how
the computer thinks and how the programmer thinks. To put it in
positive terms, we can talk about what we optimize for. We no longer
optimize only for time or space, or for lack of redundancy. We're now
trying to optimize for programmer productivity, and that implies the
ability to optimize for a host of other external constraints that vary
from job to job. The whole idea of TMTOWTDI is that it gives you more
*expressive* power. Just as in English you can express yourself in any
of several related ways depending on subtle external factors, so too in
Perl you can pick the way that optimizes for the particular task at
hand.
> conversely it diminishes its practicality by making it harder to
> write and apply a parser-generator,
Eh? I don't think parser-generators have much to do with practicality,
unless you're practicing CS in somebody's ivory tower.
> and even more significant- it
> makes it harder for programmers to learn and apply the language.
I would argue that it's *less* significant. You only learn a language
once, while you use it many times. Therefore your language should be
optimized for expressive power, not for learnability.
> Maybe Mr. Wall wanted to allow many possible
> syntaxes (syntaces?) so in the event that a programmer "forgot" one, he
> was more likely to "stumble on" to one that worked?
That is only one of the benefits of redundancy. Linguists love
redundancy. Not only does it work if you "forgot one", it also
works if you never "learned one" in the first place. It allows
people who have a partial intersection of linguistic abilities to
find a common subset that they both understand. Redundancy in
natural language also allows for "parity checks". Redundancy
allows communication over noisy channels. I submit to you that
the channel between the programmer's brain and the computer's
brain is noisy at several different levels.
> I've read many
> quotes from Mr. Wall and generally find him insightful and intuitive,
> but I'm not sure about his thoughts along these lines. One quote I
> found:
>
> "Although the Perl Slogan is There's More Than One Way to Do It, I
> hesitate to make 10 ways to do something. :-) "
> --Larry Wall in <9695@jpl-devvax.JPL.NASA.GOV>
>
>is along these lines- why make more than ONE? What did it add, Larry?
Because what I tell you three times is true. :-)
Larry
------------------------------
Date: Tue, 03 Nov 1998 16:33:25 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: PERL is TOO flexible
Message-Id: <alecler-0311981633250001@dialup-733.hip.cam.org>
[Posted and e-mailed.]
In article <MPG.10a902a76156ba85989862@nntp.hpl.hp.com>, lr@hpl.hp.com
(Larry Rosler) wrote:
> In article <alecler-0311981530250001@dialup-733.hip.cam.org> on Tue, 03
> Nov 1998 15:30:25 -0500, Andre L. <alecler@cam.org> says...
> > Well, the second one causes a compiler warning if you use -w, which
you should.
>
> No, it doesn't; and yes, you should; and *you* should try it before
> posting.
My bad. <blush> I was thinking of Daniel E. Macks' post in this thread:
> But there's a pretty big diffeence between these two:
> print "cycle ",++$cycle;
> print ("cycle "),++$cycle;
This does bring a warning if the + operator is not used.
By distraction, I answered the wrong post. Sorry about that.
Andre
------------------------------
Date: Tue, 3 Nov 1998 20:53:43 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: PERL is TOO flexible
Message-Id: <F1v61K.8CE@world.std.com>
"PERL ROCKS!" <emills@harris.com> writes:
>This is but one example I've found that seems redundant. Another:
> print "stuff\n";
> print ("stuff\n");
>What does this add?
In this case, nothing, but how about in this case?
print join("\n", @array), "\n";
Yes, the syntax could require parens around functions (like C), but
that would add useless clutter. (As opposed to "$", "@", "%", "&",
and "*" which are often argued as being useful clutter).
If you want minimalest rules, for this one the rule is "parenthesis
can be used to specify precedence in the arguments to function calls."
And if want to prohibit the parens entirely, then that wrecks perl's
variadic subroutine calling semantics, which would then diminish the
usefulness of the language.
--
Andrew Langmead
------------------------------
Date: Tue, 03 Nov 1998 21:34:41 GMT
From: jholden@voyager.net (J Holden)
Subject: perl modules
Message-Id: <71nsti$a5m@news.voyager.net>
am really getting my feet wet with perl modules and encountered this
error message
Can't locate LWP/Socket.pm in @INC and then some paths
I looked and that Socket.pm is in the path that it specifies, but I am
not sure how to make it work. Can someone show me or give me
someplace I can look to get more info?
thanks
------------------------------
Date: Tue, 03 Nov 1998 21:14:04 +0000
From: Imran Hussain <imran.hussain@csfb.com>
Subject: PROBLEMS! Installing Date:Manip
Message-Id: <363F721C.1E5519@csfb.com>
I am trying to write a Perl script on a UNIX box as an ordinary user and
need to install Date:Manip. Unfortunately I don't have the neccessary
rights to install to all the directories that the make command needs
access to.
Is there any way round this? Can access the Manip.pm from another file
or is there someway of installing it in my home area and using it from
there?
Would appreciate any help.
------------------------------
Date: Tue, 03 Nov 1998 21:38:48 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: PROBLEMS! Installing Date:Manip
Message-Id: <IJK%1.4921$fS.16068465@news.itd.umich.edu>
In article <363F721C.1E5519@csfb.com>,
Imran Hussain <imran.hussain@csfb.com> wrote:
>I am trying to write a Perl script on a UNIX box as an ordinary user and
>need to install Date:Manip. Unfortunately I don't have the neccessary
>rights to install to all the directories that the make command needs
>access to.
>Is there any way round this? Can access the Manip.pm from another file
>or is there someway of installing it in my home area and using it from
>there?
Create a directory to hold your modules--say, "/my/home/myperlmods".
When you create the module's Makefile, do this:
perl Makefile.PL LIB=/my/home/myperlmods
Then, do one of the following:
o Run your script with a -I/my/home/myperlmods switch.
o Put "use lib '/my/home/myperlmods'" in your script.
o Put "export PERL5LIB=/my/home/myperlmods" (or its local equivalent)
in your profile, or the profile of the process which will be executing
the script.
I had to do this once with Net::Telnet.
--
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: Tue, 3 Nov 1998 12:59:24 -0800
From: "Alistair Calder" <webmaster@topproducer.com>
Subject: Re: Reading multiple lines
Message-Id: <71nqqs$nqa$1@supernews.com>
Er...thanks. I am pretty much a beginning PERL programmer, and I have yet
to use a module. On top of that, I am not sure what do do with it once I
have it, I don't own the server my site is on. I wouldn't know what to do
with the module even if I did download it to my machine.
I have looked at the blue Camel book, but I am still not quite sure how
modules work or how they are implemented in a script. I guess I'll have to
pick up that knowledge.
Matt Knecht wrote in message ...
>Alistair Calder <webmaster@topproducer.com> wrote:
>>I am trying to parse an HTML document
>>
>> I
have
>>tried a number of different ways, but I just can't get it to work
properly.
>>
>>Is this going to be possible?
>
>Quite easily! Just use HTML::Parser. You should be able to find it at
>
><URL:http://www.perl.com/CPAN-local/modules/by-module/HTML/>
>
>It would proabably be wise to grab the entire libwww bundle.
>
>--
>Matt Knecht - <hex@voicenet.com>
------------------------------
Date: Tue, 3 Nov 1998 15:10:19 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reading multiple lines
Message-Id: <rfrn17.bk9.ln@flash.net>
Alistair Calder (webmaster@topproducer.com) wrote:
: What I would like to do is, instead of reading each line seperately, I'd
: like to read in the whole chunk of data and deal with it as a group.
: Is this going to be possible?
{ local $/; # look up $/ special variable in the 'perlvar' man page
$whole_darned_file = <>;
}
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 3 Nov 1998 22:42:13 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: Reading multiple lines
Message-Id: <1dhxuas.1by1qqo14whti2N@host034-210.seicom.net>
Alistair Calder <webmaster@topproducer.com> wrote:
> What I would like to do is, instead of reading each line seperately, I'd
> like to read in the whole chunk of data and deal with it as a group. I have
> tried a number of different ways, but I just can't get it to work properly.
I'm not sure what you mean by "group". To store the whole file in one
big scalar you can manipulate the $INPUT_RECORD_SEPARATOR ($/) variable.
undef $/;
$the_whole_file = <FILEHANDLE>;
Now you can do whatever you want with $the_whole_file. This might use a
lot more resources than doing the job line by line.
hth, HANW,
Joergen
--
To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
"Everything is possible - even sometimes the impossible"
HOELDERLIN EXPRESS - "Touch the void"
------------------------------
Date: 3 Nov 1998 20:28:43 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: replicating `more`
Message-Id: <71np1r$q2$1@gellyfish.btinternet.com>
On Tue, 03 Nov 1998 02:26:26 +0000 WMWilson <m.v.wilson@erols.com> wrote:
> Anyone know where I can find out about replicating the more (or pg)
> command?....Preferrably something simple.
This is so simple it should be placed in an institution for the
educationaly subnormal - you will need to adjust $lines to whatever is
appropriate on your system of course:
#!/usr/bin/perl
require Term::Cap;
my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => 9600};
my $clear = $terminal->Tputs('cl',1);
$lines = 20;
my $reverse = $terminal->Tputs('mr',1);
my $endmode = $terminal->Tputs('me',1);
print $clear;
while(<>)
{
print;
if(++$done == $lines)
{
print $reverse,"-- MORE --",$endmode;
my $blah = <STDIN>;
$done = 0;
print $clear;
}
}
__END__
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Wed, 04 Nov 1998 10:01:27 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Shell built-in commands in a perl script?
Message-Id: <363F6F27.1BAE36D4@cardinal.co.nz>
Tk Soh wrote:
>
> On the matter of efficiency:
>
> perldoc -f exec:
> ...
> If there is only one scalar argument or an array with one element in it,
> the argument is checked for shell metacharacters and if there are any,
> the entire argument is passed to the system's command shell for parsing
> If there are no shell metacharacters in the argument, it is split into
> words and passed directly to C<execvp()>, which is more efficient.
> ...
>
> system("ls") seems much faster than system("csh -c 'ls'"). how does this
> fit into the text above?
The original poster said 'source' was a shell built-in command, whereas
'ls' is not (Type "type ls" at a command prompt, then type "type pwd".
One will identify the full path, the other will say shell builtin ).
Therefore system("ls") will find and execute the 'ls' command, but
system("source <filename>") would not find an executable called source
to run. Running sh -c ( where sh could be bsh, csh or ksh ) would fire
up a shell which would understand a builtin command. Given the
statements on using system with scalar versus list arguments, it may be
that system("source <filename>","#comment") would work also. As has
been stated already, using the system command will just run the command
and not return any output to the caller which may not be what he wanted
rendering the bulk of this discussion academic.
> Does "system's command shell" refer only to /usr/bin/sh?
In the Unix world I imagine it would depend on your parent shell and/or
the value of the SHELL environment variable. In Win32, I suspect
CMD.EXE is called regardless.
>
> -tk
------------------------------
Date: Tue, 03 Nov 1998 19:59:35 GMT
From: anthonyr1234@my-dejanews.com
Subject: single quotes in filename
Message-Id: <71nnb7$3cf$1@nnrp1.dejanews.com>
I need to fetch a file whose name contains single quotes using the Net::FTP pm
.
The FTP command line would look like this: get 'foo.bar'
I have tried the following method with every variation of quotes/backslashes
with no success:
$file = "'foo.bar'";
$ftp->get($file);
My assumption is that the get method is interpolating the single quotes
somewhere.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
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 4142
**************************************