[6755] in Perl-Users-Digest
Perl-Users Digest, Issue: 380 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 27 09:07:22 1997
Date: Sun, 27 Apr 97 06:00:30 -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 Sun, 27 Apr 1997 Volume: 8 Number: 380
Today's topics:
$#array test fails ??? (Geoffrey Hebert)
Re: $#array test fails ??? (Honza Pazdziora)
ANNOUNCE: ePerl 2.1.0 (Embedded Perl 5 Language) (Ralf S. Engelschall)
Banner Ad Perl Scripts?? <herbr@pfinders.com>
Re: Lisp is neither (was Re: Ousterhout and Tcl lost th (Bjxrn Remseth)
Re: Lisp is neither (was Re: Ousterhout and Tcl lost th (Bjxrn Remseth)
Need Help making random number! (Jake Shin)
Re: Object IDs are bad (was: Ousterhout and Tcl lost th (Andrew Koenig)
Re: Object IDs are good ( was: Object IDs are bad ) (Matthias Blume)
Re: quote of the day? (Honza Pazdziora)
recursive opendir(),readdir....efficient algorithm? (Otis Gospodnetic)
Re: recursive opendir(),readdir....efficient algorithm? (Nathan V. Patwardhan)
Re: Removing 2 or more spaces ? (Nathan V. Patwardhan)
Setting UID from CGI script <markbuch@mail.superlink.net>
Re: STDOUT | PAGER (Chipmunk)
Re: switch and if (John Nolan)
Re: Trouble with Emacs auto formatter (Chipmunk)
Re: Unix and ease of use (WAS: Who makes more ...) (Michael Hoffman)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 27 Apr 1997 05:20:55 GMT
From: soccer@microserve.net (Geoffrey Hebert)
Subject: $#array test fails ???
Message-Id: <5jumlu$q61$1@news3.microserve.net>
OK this one stumps me.
This test works when there are more than 3 items in the array.
$word=shift(@aline);
print '$#aline is '."$#aline\n";
if ($#aline>0) {$page_title=shift(@aline)}
if ($#aline>0) {print "found page title $page_title\n"}
Results when $#aline is 3 - seems to work fine.
$#aline is 3
found page title new.cgi
Results when $#aline is 1 - fails - notice no print found page
$#aline is 1
while (uc(000) ## this is a print later in the test.
------- signature ----------
Check out the Perl site!
http://www.microserve.net/~soccer/
use password perlmisc
Geat tool for Developers>
------------------------------
Date: Sun, 27 Apr 1997 11:52:59 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: $#array test fails ???
Message-Id: <adelton.862141979@aisa.fi.muni.cz>
soccer@microserve.net (Geoffrey Hebert) writes:
> OK this one stumps me.
> This test works when there are more than 3 items in the array.
>
> $word=shift(@aline);
> print '$#aline is '."$#aline\n";
> if ($#aline>0) {$page_title=shift(@aline)}
> if ($#aline>0) {print "found page title $page_title\n"}
>
> Results when $#aline is 3 - seems to work fine.
> $#aline is 3
> found page title new.cgi
>
> Results when $#aline is 1 - fails - notice no print found page
> $#aline is 1
> while (uc(000) ## this is a print later in the test.
It looks like you are missing a point about the meaning of $#aline. It
means the index of the last element in the array @aline. So
if ($#aline>0)
is true iff there are at least two elements in the @aline array. Which
is true if you start with at least found elements, since you do two
shifts before the second if.
Hope I answered your question.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: 27 Apr 1997 10:14:32 GMT
From: rse@engelschall.com (Ralf S. Engelschall)
Subject: ANNOUNCE: ePerl 2.1.0 (Embedded Perl 5 Language)
Message-Id: <5jv8u8$6da$1@en1.engelschall.com>
____ _
___| _ \ ___ _ __| |
/ _ \ |_) / _ \ '__| |
| __/ __/ __/ | | |
\___|_| \___|_| |_|
ePerl -- Embedded Perl 5 Language
<URL:http://www.engelschall.com/sw/eperl/>
Version 2.1.0 (26-04-1997)
ePerl interprets an ASCII file bristled with Perl 5 program statements
by evaluating the Perl 5 code while passing through the plain ASCII
data. It can operate both as a standard Unix filter for general file
generation tasks and as a powerful Webserver scripting language for
dynamic HTML page programming.
Copyright (c) 1996-1997 Ralf S. Engelschall, All rights reserved.
______________________________________________________________________
Implementation: - ANSI C
Requirements: - underlaying Unix derivate
- ANSI C compiler
- installed Perl 5.003 (+EMBED) or 5.003_XX
Distribution: - freely available
- no charge
- GNU General Public License or Artistic License
Status: - Genesis: Februar 1996
- First public release: March 1996 (1.0)
- Last public release: Januar 1997 (2.0.3)
- stable
______________________________________________________________________
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
------------------------------
Date: Sat, 26 Apr 1997 21:31:02 -0700
From: Herb Rubin <herbr@pfinders.com>
Subject: Banner Ad Perl Scripts??
Message-Id: <3362D686.3047@pfinders.com>
Does anybody know of banner ad Perl scripts that I can tinker with.
Thanks in advance,
Herb Rubin
------------------------------
Date: 27 Apr 1997 12:22:47 +0200
From: rmz@hridil.ifi.uio.no (Bjxrn Remseth)
Subject: Re: Lisp is neither (was Re: Ousterhout and Tcl lost the plot)
Message-Id: <ajiv18ydc8.fsf@hridil.ifi.uio.no>
"M. Prasad" <prasadm@polaroid.com> writes:
> We seem to have lots of opinions, with a fair amount
> of blame placement on management. But you don't get to manage
> a start-up with that many high-powered brains, unless
> you are really good and proven. So I still doubt the
> "bad management" theory very much.
Didn't say it was "bad", and I don't remember mentioning blame
anywhere in my message. Perhaps what I described was good management
in practice, perhaps the lisp machines deserved to die, and the
mechanisms i sketched out was just how they went about to do it.
--
(Rmz)
Bj\o rn Remseth !Institutt for Informatikk !Net: rmz@ifi.uio.no
Phone:+47 22855802!Universitetet i Oslo, Norway !ICBM: N595625E104337
------------------------------
Date: 27 Apr 1997 13:28:18 +0200
From: rmz@hridil.ifi.uio.no (Bjxrn Remseth)
Subject: Re: Lisp is neither (was Re: Ousterhout and Tcl lost the plot)
Message-Id: <ajg1wcyab1.fsf@hridil.ifi.uio.no>
"M. Prasad" <prasadm@polaroid.com> writes:
> We seem to have lots of opinions, with a fair amount
> of blame placement on management. But you don't get to manage
> a start-up with that many high-powered brains, unless
> you are really good and proven. So I still doubt the
> "bad management" theory very much.
Didn't say it was "bad", and I don't remember mentioning blame
anywhere in my message. Perhaps what I described _was_ good
management in practice, perhaps the lisp machines deserved to die, and
the mechanisms i sketched out was just how they went about to do it?
I simply don't make any judgement one way or the other, I observe
and try as best I can to understand.
--
(Rmz)
Bj\o rn Remseth !Institutt for Informatikk !Net: rmz@ifi.uio.no
Phone:+47 22855802!Universitetet i Oslo, Norway !ICBM: N595625E104337
------------------------------
Date: 27 Apr 1997 04:40:51 GMT
From: "=E@gH#(Jake Shin)" <netj@nuri.net>
Subject: Need Help making random number!
Message-Id: <01bc52c5$58ea0d20$4571e8cb@Kornet.soback.kornet.nm.kr>
Hi All?
I'm trying to make randomized number.
but I don't know the method.
Please Help.
If you know how I would Greatly Appreciate it.
Jake Shin,
from Korea
------------------------------
Date: Sun, 27 Apr 1997 12:07:40 GMT
From: ark@research.att.com (Andrew Koenig)
Subject: Re: Object IDs are bad (was: Ousterhout and Tcl lost the plot with latest paper)
Message-Id: <E9Apos.DLI@research.att.com>
In article <3071056971024295@naggum.no> Erik Naggum <erik@naggum.no> writes:
> I have no idea whether Peter Ludemann had a third meaning of "object
> identity" in mind, and I don't know whether Andrew Koenig knows ML well
> enough that it is true that ML doesn't offer object identity, but it seems
> rather obvious to offer object identity if you offer composite types. what
> little I know about ML suggsts that ML _must_ offer object identity. (how
ML does not offer object identity, because it doen't have objects.
The closes it has is references, which are mutable cells that contain
values. Two references have the same value iff they are the same reference
(although two distinct references can contain the same value). Example:
val x = ref 3;
Now x is bound to a reference that contains the value 3.
val y = ref 3;
Now y is bound to a different reference that contains the value 3.
Therefore, x = x is true, x = y is false, and !x = !x and !x = !y are both true
(! is the dereferencing operator in ML).
If you do not references, values are all you have. So, for example
val p = [3, 4, 5];
val q = [3, 4, 5];
Now p = q because p and q have the same value, and there is no way to determine
whether p and q are the same list because even the question is meaningless in ML.
(The implementation might store p and q as pointers to the same memory,
or it might not. There is no way to tell.)
--
--Andrew Koenig
ark@research.att.com
http://www.research.att.com/info/ark
------------------------------
Date: 25 Apr 1997 11:27:55 -0400
From: blume@mocha.cs.princeton.edu (Matthias Blume)
Subject: Re: Object IDs are good ( was: Object IDs are bad )
Message-Id: <izhggvrukk.fsf@mocha.CS.Princeton.EDU>
In article <33607944.3852@ws6a17.gud.siemens.co.at> "Istvan.Simon" <simo@ws6a17.gud.siemens.co.at> writes:
Even if two things LOOK the same then they are not the same. If they
were the same you could never make a copy from anything. If this is
true in reality then there is no reason to be untrue in programming
languages.
Several misconceptions:
- There are things in the "real" world that don't have an "identity".
Numbers are one example, and we generally don't expect to be able
to distinguish between _this_ 1 and _that_ 1. Another example is the
electron (or other thingies that particle physicists might be interested
in).
- Things that _actually_ look the same in each and every
respect_are_ the same. Things that we can distinguish between
do _not_ look the same (by definition -- this is what we mean by
being able to distinguish).
- Even if, for a moment, we assume that all "real world" things have an
inherent identity (the electron is a nice counterexample), then
it is _still_ a bad idea to extrapolate from this and make every
value in a programming language the same. Abstract things (like
numbers, functions, sets) do _not_ have an identity.
- From a denotational point of view object identity doesn't matter
for immutable things.
- Exactly _because_ there is no notion of identity, and because
things that look the same _are_ the same, it is possible for the
compiler to make copies of things (or represent them differently
at different times during execution). This is of great value for
optimizing compilers.
You always have a memory address even you don't want to have one.
This address will identify your object even if you don't want it.
See, here is the mistake. If you don't have the concept of identity,
then the compiler can choose to duplicate things when it needs to, it
can keep things in registers instead of bundling them up and allocate
them on the heap, it can use a hash-consing GC that identifies
lookalikes the programmer didn't think of and represent them by the
same "pointer" internally, and so on. Once you do any of this, you
don't have _one_ pointer that identifies your value -- there might be
two, or ten, or none at all.
--
-Matthias
------------------------------
Date: Sun, 27 Apr 1997 11:56:38 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: quote of the day?
Message-Id: <adelton.862142198@aisa.fi.muni.cz>
mosey@alpha2.csd.uwm.edu (John Thomas Mosey) writes:
> I'd like to make a quote of the day script, only I don't know the syntax
> to call the day. What code to I use to check what day of the month it is?
You need functions localtime and time. According to man page for
localtime
Typically used as follows:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
print((localtime)[3], "\n");
will print 27 today.
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: 27 Apr 1997 05:35:30 GMT
From: otisg@tiger.middlebury.edu (Otis Gospodnetic)
Subject: recursive opendir(),readdir....efficient algorithm?
Message-Id: <5juoj2$1a2q@tiger.middlebury.edu>
Hi,
I was playing with opendir(), readdir(), etc. and decided to try going through
our news spool and look for, for example, articles that are 1 hour old.
So I wrote this short script (below) and let it run.
Well, it's either very inefficient or the amount of new is really so great
that it takes over 1 hour (I gave up after 60 minutes of waiting) to run.
In any case, can anyone suggest any way(s) to improve the efficiency (both
coding-wise and algorithm-wise) ?
here's the code:
&traverse ($spool); # spool is the base NNTP spool directory
sub traverse {
my ($dir) = shift;
my ($path);
my (@files);
opendir(DIR,$dir) || die "Can't open DIR $dir: $!\n";
@files = readdir(DIR);
closedir(DIR);
foreach (@files) {
next if (($_ eq ".") || ($_ eq ".."));
$path = "$dir/$_";
if (-d $path) { # directory? traverse it
&traverse ($path);
}
else { # file? keep going
if ( time - (stat $path)[9] > 600 ) {
print "Skipping: $path\n"; # skip posts older than 600 seconds
next;
}
else {
&parsepost ($path); # parse posts < 600 old
}
}
}
}
sub parsepost {
my ($post) = shift;
print "POST: $post\n"; # just prints the post or whatever
}
__END__
Thanks !
Otis
------------------------------
Date: 27 Apr 1997 06:54:34 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: recursive opendir(),readdir....efficient algorithm?
Message-Id: <5jut7a$ieg@fridge-nf0.shore.net>
Otis Gospodnetic (otisg@tiger.middlebury.edu) wrote:
: I was playing with opendir(), readdir(), etc. and decided to try going through
: our news spool and look for, for example, articles that are 1 hour old.
Use find2perl or File::Find just as you would use find on your OS.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 27 Apr 1997 06:52:14 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Removing 2 or more spaces ?
Message-Id: <5jut2u$ieg@fridge-nf0.shore.net>
C Carr (clint@netcom.com) wrote:
: Is there a quick way to remove two or more spaces in a variable?
Get the FAQ now.
lynx http://www.perl.cpm/FAQ
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Sun, 27 Apr 1997 03:00:25 -0400
From: Mark Buchanan <markbuch@mail.superlink.net>
Subject: Setting UID from CGI script
Message-Id: <3362F989.38F3@mail.superlink.net>
All,
I am wondering if the following can be done, I am running Apache web
server with .htaccess and .htpasswd files. I wrote a Perl 5 CGI script
that will need access to write to the .htpasswd file (644 root root
permissions) in order to change the password from the CGI script. I
have the script working, but I need to be root in order to do this. Can
I set UID from a Perl script (I am UID -1 when the script runs).
In other words, can I setuid or suid? Do I need a syscall to do
this? I can't find anything from the Camel or other books I have.
Frustrated and alone,
Mark
mailto:markbuch@mail.superlink.net
------------------------------
Date: 27 Apr 1997 05:25:56 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: STDOUT | PAGER
Message-Id: <5juo14$odq$2@dartvax.dartmouth.edu>
In article <Pine.GSO.3.96.970423212731.7796D-100000@kelly.teleport.com>
Tom Phoenix <rootbeer@teleport.com> writes:
> On 23 Apr 1997, Chipmunk wrote:
>
> > My perl program pipes some of its output through a pager:
> > $pager = $ENV{PAGER} || 'more';
> > open (PAGER, "| $pager") or *PAGER = *STDOUT;
>
> Hmmm.... Do you know what happens if someone's selected pager can't be
> run?
I suppose it just makes PAGER a reference to STDOUT. I should probably
test it to see what happens, huh?
> > Unfortunately, if the pager is more, and I exit more in the middle of
> > the output by typing 'q', my perl program exits with the message
> > 'Broken Pipe'.
> >
> > How can I make the perl continue execution normally if someone exits
> > the pager before reaching the end of the output?
>
> Have you tried catching the SIGPIPE? Hope this helps!
Yup, thanks to tips from a few clpm posters, I'm now trapping the
SIGPIPE signal and my code works nicely.
Chipmunk
------------------------------
Date: Sun, 27 Apr 1997 12:35:50 GMT
From: sg94bwh5@dunx1.ocs.drexel.edu (John Nolan)
Subject: Re: switch and if
Message-Id: <41b7cd$72332.8c@XAVIER>
Perl does not have a switch statement per se, i.e., there is no
"switch" keyword. But there are a number of constructs
which behave just like a switch construct would...
in fact, for all intents and purposes, these *are* switch
statements, even though they're not. (Get it?)
By using one of these constructs, you can make the same
efficiency gains over if/else that you would make by using
a switch statement. Alternatively, you can skip efficiency
and just use if/else statements. Whaddeva.
This is explained in detail in the Camel book, as was already posted here.
Go check it out. :)
PS - you can also write effective case/switch statements
using a pencil. But that's another story. ;)
Alastair Aitken (a.aitken@unl.ac.uk) wrote:
: iqbal gandham wrote:
: > Chipmunk wrote:
: > > In article <335E3B6E.39D8@prestel.net>
: > > iqbal gandham <igandham@prestel.net> writes:
: > >
: > > > Is it better to use an if statement or switch, or doesn't it make much
: > > > difference.
: > > You are absolutely right about that. There is no reason to use
: > > multiple if/else statements like that in Perl, when Perl's switch
: > > statement will do the same thing much more efficiently.
: > >
: Ok - confused now. I thought, as Abigail said, that there was no
: switch/case statement in perl and
: that effective switch/case statements coud be written using
: if/elsif/else constructs.
: I think Chipmunk is wrong here .. or amd I?
--
### John Nolan
### jpn@acm.org ~ __0
### sg94bwh5@dunx1.ocs.drexel.edu ~ _`\<,_
### Drexel University, Philadelphia ~ (_)/ (_)
Life is full of shadows but the sunshine makes them all.
-- Anonymous
------------------------------
Date: 27 Apr 1997 05:12:27 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Trouble with Emacs auto formatter
Message-Id: <5jun7r$odq$1@dartvax.dartmouth.edu>
In article <5ju122$2ic$1@mathserv.mps.ohio-state.edu>
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> I think HERE-docs are handled even without a patch to Emacs. I do not
> remember exactly, though.
Here's what emacs wants to do with my here documents:
&do_something {
print <<EndOfText;
Hello World
EndOfText
}
Unfortunately, it looks like the system I'm on has a rather old version
of emacs.
This is the same system that has perl5 installed but still has the
perl4 manpages. This sysadmin is a bit clueless sometimes, I think.
Chipmunk
------------------------------
Date: Sun, 27 Apr 1997 02:32:12 GMT
From: mhoffman@wpo.borland.com (Michael Hoffman)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <3362b7a3.32577623@news.borland.com>
On 18 Apr 1997 16:40:08 -0400, psmith@baynetworks.com (Paul D. Smith)
wrote:
>%% Douglas Seay <seay@absyss.fr> writes:
>
> ds> Martin Sohnius x24031 wrote:
>
> >> * if (status = UNDER_NUCLEAR_ATTACK) *
> >> * launch_full_counterstrike(); *
>
> ds> Well, Martin old boy, this is why Reagan's Star Wars (aka SDI)
> ds> frigtened me. You assign the value UNDER_NUCLEAR ATTACK to
> ds> status. If this value is non-zero, then you call
> ds> launch_full_counterstrike(). The value of status was never
> ds> consulted, just changed to UNDER_NUCLEAR_ATTACK.
>
>Giving Martin the benefit of the doubt, perhaps that's the point?
>
>I, at least, find it a more interesting .sig this way than the "right"
>way. But some say I have a strange sense of humor.
>
>Ha ha.
>
>:)
>
>--
>-------------------------------------------------------------------------------
> Paul D. Smith <psmith@baynetworks.com> Network Management Development
> "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
>-------------------------------------------------------------------------------
> These are my opinions--Bay Networks takes no responsibility for them.
Using this sig, I wrote one of my first C programs, to demonstrate
this error. Even though status is set to ALL_QUITE in get_status,
launch_full_counterstrike() is called, rather than keep_cool() as
intended. This compiles and runs, but Borland C++ 5.02 does warn
about the "if" statement -- specifically, right before the "="
character: "Possibly incorrect assignment".
Obviously, everyone in all the followup newsgroups will want to run my
cool, highly relevant program that demonstrates the bug:
comp.databases
comp.infosystems.www.advocacy
comp.lang.c
comp.lang.c++
comp.lang.javascript
comp.lang.perl.misc
comp.lang.tcl
comp.object
comp.os.linux.advocacy
comp.os.ms-windows.advocacy
comp.unix.advocacy
Now I am ready to write programs for the Department of Defense.
#include <stdio.h>
#define ALL_QUIET 0
#define UNDER_NUCLEAR_ATTACK 1
int main (void)
{
int status;
// function prototypes:
int launch_full_counterstrike(void);
int get_status(void);
int keep_cool(void);
status = get_status();
if (status = UNDER_NUCLEAR_ATTACK)
launch_full_counterstrike();
else
keep_cool();
return 0;
}
int get_status()
{
int current_status = ALL_QUIET;
return current_status;
}
int keep_cool()
{
printf("\nEverything's cool.");
return 0;
}
int launch_full_counterstrike()
{
printf("\n\n BOOM!!! \n\n");
return 0;
}
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
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 380
*************************************