[12502] in Perl-Users-Digest
Perl-Users Digest, Issue: 6102 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 23 01:07:13 1999
Date: Tue, 22 Jun 99 22: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 Tue, 22 Jun 1999 Volume: 8 Number: 6102
Today's topics:
Re: [Req:] Date::Abigail (Lee)
Re: A buggy intersection-method <rra@stanford.edu>
Re: Can I do this? Conditional Operator construct.... <tchrist@mox.perl.com>
Re: Can I do this? Conditional Operator construct.... (Larry Rosler)
Re: Displaying Adds (Tad McClellan)
Re: Displaying Adds (Tad McClellan)
Re: Exit values on NT, and run via AT <walton@frontiernet.net>
Re: function to read a line & return it (Ronald J Kimball)
Hashes of Array's...FUN! and question. (Mitch)
Re: Hashes of Array's...FUN! and question. (Eric Bohlman)
Re: Hashes of Array's...FUN! and question. (Andrew Johnson)
Re: Having an external script modify %ENV? <rra@stanford.edu>
How to start perl server with inetd.. (?) <alex@sea.wa.com>
Java servlet vs mod_perl(was Re: Does Perl have a futur <watcher_q@my-deja.com>
Re: Newbie - Perl books - which to get? brad.kruse@pobox.com
Re: Newbie - Perl books - which to get? <ranaylor@cais.net>
Perl and Personal Web Server (Win98) chitown34@my-deja.com
Re: perl equivalent of #INCLUDE? (Tad McClellan)
Re: Piping through Less. (Ronald J Kimball)
Re: Statistics for comp.lang.perl.misc (Ronald J Kimball)
Re: Summing an array (Mark-Jason Dominus)
Re: Summing an array <uri@sysarch.com>
Re: Summing an array <rra@stanford.edu>
Timing out problem...Suggestions? <portboy@home.com>
Re: To obfuscate or not? <rra@stanford.edu>
We need you help to find some links, documents, sources <fred@decatomb.com>
webget, perl 5.005_03 on Linux, cryptic error (marek jedlinski)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Jun 1999 21:42:53 -0500
From: rlb@intrinsix.ca (Lee)
Subject: Re: [Req:] Date::Abigail
Message-Id: <B395B3DD966822D67F@204.112.166.88>
In article <377027EA.77042D48@mail.cor.epa.gov>,
David Cassell <cassell@mail.cor.epa.gov> wrote:
>Lee wrote:
>> [an entertaining sub]
Thanks. I just looked it over and found two bugs. I hope this doesn't ruin
anyone's production code. :)
Lee
------------------------------
Date: 22 Jun 1999 21:33:33 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: A buggy intersection-method
Message-Id: <ylemj3h6xu.fsf@windlord.stanford.edu>
Greg Bacon <gbacon@itsc.uah.edu> writes:
> bart.lateur@skynet.be (Bart Lateur) writes:
>> Oh. That reminds me. I've tried this:
>> {
>> local *ARGV;
>> @ARGV = ('/some/file');
>> while(<>) {
>> ...
>> }
>> }
>> but I noticed that localizing the filehandle ARGV (which was part of
>> what I wanted) mad it loose it's magic properties. I guess that by
>> default, ARGV is a tied handle, and no longer if localized. I just
>> thought I'd mention this.
> Apparently it has something to do with localizing the typeglob. This
> works (on Linux, at least):
> #! /usr/bin/perl -w
> use strict;
> {
> local @ARGV = 'ps auxww |';
> while (<>) { print }
> }
Yes, but this clobbers your ARGV file handle if something else is doing
something with it. I think that's what Bart was trying to avoid.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 22 Jun 1999 20:30:07 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Can I do this? Conditional Operator construct....
Message-Id: <377046af@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
portboy@home.com (Mitch) writes:
:TEST_EXPR ? $some_value = 1; $other_value =0 : IF_FALSE_EXPR
(TEST_EXPR) ? ($some_value, $other_value) = (1, 0) : IF_FALSE_EXPR
--tom
--
An unbreakable tool is useful for breaking other tools.
------------------------------
Date: Tue, 22 Jun 1999 19:45:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can I do this? Conditional Operator construct....
Message-Id: <MPG.11d9e9fde673a0a7989c2a@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <376fca89.345284973@24.0.3.71> on Wed, 23 Jun 1999 01:40:18
GMT, Mitch <portboy@home.com> says...
> I'm trying to use the format for "Conditional Operator" of TEST_EXPR ?
> IF_TRUE_EXPR : IF_FALSE_EXPR
>
> This works fine, but my question is...Can I do this?
>
> TEST_EXPR ? $some_value = 1; $other_value =0 : IF_FALSE_EXPR
> ^
> I don't seem to be able to do this...Is there a way of accomplishing
> this in this type of format?
Take your pick.
TEST_EXPR ? $some_value = 1, $other_value = 0 : IF_FALSE_EXPR
TEST_EXPR ? do { $some_value = 1; $other_value = 0 } : IF_FALSE_EXPR
TEST_EXPR ? ($some_value, $other_value) = (1, 0) : IF_FALSE_EXPR
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 22 Jun 1999 17:53:34 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Displaying Adds
Message-Id: <uk0pk7.f21.ln@magna.metronet.com>
Tom Christiansen (tchrist@mox.perl.com) wrote:
: [courtesy cc of this posting mailed to cited author]
: In comp.lang.perl.misc, tadmc@metronet.com (Tad McClellan) writes:
: :# script to display some adds (sic)
: :use strict;
: :my @adds = ('1+1', '2+1', '1+2', '2+2');
: :my $i =0;
: :while (1) {
: : print "$adds[$i]\n";
: : sleep 5;
: : $i++;
: : $i = 0 if $i == 3;
: :}
: I think you forgot an eval() in there; or perhaps preferably, a
: Safe->new->reval() instead.
But that would display some "sums", he wanted to display some "adds".
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 22 Jun 1999 17:55:01 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Displaying Adds
Message-Id: <ln0pk7.f21.ln@magna.metronet.com>
Matthew Bafford (dragons@dragons.duesouth.net) wrote:
: ::Tue, 22 Jun 1999 21:30:04 GMT::j_a_p@my-deja.com::j_a_p@my-deja.com::Displaying Adds::<7kov8d$kn1$1@nnrp1.deja.com>::comp.lang.perl.misc::
: : I want to write a simple function that displays adds and changes the
^^^^
^^^^
: : picture every so often.
: [snipza!]
: Here's one that displays a new add every time it's called:
^^^
^^^
Stop the madness!!!
You guys aren't really displaying "add"itions are you?
Surely you mean "ads" as in "ad"vertisement?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 22 Jun 1999 23:26:44 -0400
From: Bob Walton <walton@frontiernet.net>
To: "Mark H. Wood" <mwood@mhw.ULib.IUPUI.Edu>
Subject: Re: Exit values on NT, and run via AT
Message-Id: <377053F3.3543047E@frontiernet.net>
"Mark H. Wood" wrote:
> I've installed ActiveState's Perl port on an NT box, and I'd like to
> run a script daily out of the scheduler service (AT and friends). My
> ...
> Are there any special tricks to making AS Perl run well out of the
> scheduler?
>
...
Yes. NT's AT command is pretty braindead. You should try running a
batfile under AT that does nothing but put the "path" the script is
receiving out to a file so you can see it. Probably Perl isn't on the
path AT supplies to the script (where *does* it get those crazy values
for "path", anyway?). So you might have to run your Perl script from a
batfile after setting up a proper path (one that includes Perl) in the
batfile. Also, bear in mind that your drive mappings aren't passed to
the script either, so you'll have to use UNC paths for anything over the
network. And to do that (depending on your security setup), you'll
probably need to specify your userID and password for the script to be
run under, since whatever default user ("system user"?) it runs under
probably doesn't have permissions to muck with stuff on your network.
And how to do that changed between sp3 and sp4. And then, when you
change your login password in the future, you have to change your
password there, too -- try and remember that one six months from now!
Microsoft made that one *real* user friendly :-(.
------------------------------
Date: Wed, 23 Jun 1999 00:23:24 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: function to read a line & return it
Message-Id: <1dttpex.w9nv5i1lq29g8N@p15.tc5.metro.ma.tiac.com>
Eric The Read <emschwar@rmi.net> wrote:
> "John A. Grant" <zjagrantz@znrcanz.gcz.ca> writes:
> > Ok, that makes sense. Since I'm calling the function like this:
> > my $lineoftext=ReadLine();
> >
> > then it should either "return $_" (success) or "return undef" (failure).
>
> Not quite. If you "return undef;", then what will be returned is this:
>
> (undef)
>
> What you want is
>
> undef
>
> Note the difference: one is an array containing one entry, which has the
> value undef. The other is undef itself. You want "return ();" or simply
> "return;" by itself.
>
I fail to understand the distinction you are making here.
First, (undef) is not an array, it is a list.
Second, (undef) is a list only if it is in a list context.
Third, parentheses do not equate to list. In general, list context
creates a list. Parentheses are used to create lvalue lists, but other
than that parentheses are used only for precedence.
Fourth, as rvalues and apart from issues of precedence, (undef) and
undef are interchangeable. $a = (undef) and $a = undef do the same
thing. @a = (undef) and @a = undef do the same thing.
In fact, if you define two subroutines as follows
sub foo { return undef; }
sub bar { return (undef); }
then $a = &foo and $a = &bar do the same thing.
On the other hand, (undef) and () are rather different beasties.
Perhaps that is the distinction you meant to make.
[On the gripping hand, I expect there will be corrections or
clarifications of my above points. :) ]
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 23 Jun 1999 03:40:21 GMT
From: portboy@home.com (Mitch)
Subject: Hashes of Array's...FUN! and question.
Message-Id: <376fe6a6.352481281@24.0.3.71>
Currently I've read a configuration file into a hash of arrays. So,
let's say that the config was:
coke rules
coke sucks
coke bites
I easily slurp that in, and can print this out like this:
my($var, $value);
while(($var, $value) = each %config) {
if ($var =~ /^coke/) {
print "$var @$value\n";
}
}
and get:
coke rules sucks bites
However, print this stuff back out to the configuration in the manner
it came in. So, I'd like to printout all values of "coke" to the
config file like:
coke rules
coke sucks
coke bites
instead of coke rules sucks bites....
How can I do this?
Thanks, mitch
------------------------------
Date: Wed, 23 Jun 1999 04:24:24 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Hashes of Array's...FUN! and question.
Message-Id: <ebohlmanFDrIwo.BHH@netcom.com>
Mitch (portboy@home.com) wrote:
: coke rules
: coke sucks
: coke bites
:
: I easily slurp that in, and can print this out like this:
:
: my($var, $value);
: while(($var, $value) = each %config) {
: if ($var =~ /^coke/) {
: print "$var @$value\n";
: }
: }
:
:
: and get:
:
: coke rules sucks bites
:
: However, print this stuff back out to the configuration in the manner
: it came in. So, I'd like to printout all values of "coke" to the
: config file like:
:
: coke rules
: coke sucks
: coke bites
Change your print line to
print map {"$var $_\n"} @$value;
or (5.005 and above only)
print "$var $_\n" foreach (@$value);
------------------------------
Date: Wed, 23 Jun 1999 04:27:11 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Hashes of Array's...FUN! and question.
Message-Id: <zmZb3.588$Q4.167343@news1.rdc1.on.wave.home.com>
In article <376fe6a6.352481281@24.0.3.71>,
Mitch <portboy@home.com> wrote:
! Currently I've read a configuration file into a hash of arrays. So,
[snip]
! However, print this stuff back out to the configuration in the manner
! it came in. So, I'd like to printout all values of "coke" to the
! config file like:
!
! coke rules
! coke sucks
! coke bites
!
! instead of coke rules sucks bites....
OWTDI
while(my($k,$v) = each %config){
print "$k ";
print join("\n$k ",@$v),"\n";
}
toss in a conditional if you only want to print
when $k =~ /^coke/.
regards
andrew
------------------------------
Date: 22 Jun 1999 20:09:11 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Having an external script modify %ENV?
Message-Id: <ylk8svhaug.fsf@windlord.stanford.edu>
Andrew Khazanov <akhazano@oacis.com> writes:
> Exactly. I want a _shell_ script called by Perl to modify _Perl's_
> environment. I didn't find the answer in the FAQ or in newsgroup
> archives... (I wouldn't post without looking first). I will have to do
> something like your example above (by parsing the scripts) if what I
> want is impossible.
Another approach is to modify the shell script to, rather than setting the
variables, print out the variable settings in the form <variable>=<value>.
Then, in Perl, open a pipe from the script when you run it, parse its
output with ($variable, $value) = split ('=', $_, 2), and then do
$ENV{$variable} = $value.
Whether that's easier depends on the situation.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 22 Jun 1999 20:45:21 +0100
From: "Alex G." <alex@sea.wa.com>
Subject: How to start perl server with inetd.. (?)
Message-Id: <376FE7D1.D876C542@sea.wa.com>
Hi, could anybody tell me how to install a simple server in inetd.conf.
The server works _alone_ just fine(I can start, and terminate it any
time)
However, when inetd is listening on the servers' port, the socket
wouldn't return,,
apparently it can't use the port used by inetd ???
It only works for the first time, when new port is assigned.
After that, if the process goes away, it can't be started again...
#!/usr/bin/perl -w
use IO::Socket;
use Net::hostent;
$PORT = 9000;
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server; ##<< and it dies every
time
---------------------------------------------------------------------
# grep testserver /etc/services
testserver 9000/tcp # test server
# grep testserver /etc/inetd.conf
testserver stream tcp nowait root /home/alexg/bin/server
# netstat -a |grep testserver
tcp 0 0 *:testserver *:*
LISTEN
Thanks,
-Alexander.
------------------------------
Date: Wed, 23 Jun 1999 02:11:24 GMT
From: Watcher <watcher_q@my-deja.com>
Subject: Java servlet vs mod_perl(was Re: Does Perl have a future?)
Message-Id: <7kpfo5$q67$1@nnrp1.deja.com>
In article <376ff70a.2168383@news.force9.net>,
joechan25@hotmail.com (Joe Chan) wrote:
> Hi, I was asking in my ISP's cgi newsgroup about the possibility of
> installing mod_perl. This is the reply I got from another user
>
> There are a number of downsides to doing this:
> 1) Memory usage. The Apache process can take up large amounts of
> memory if a lot of different modules are requested and a lot of
> different scripts are run.
Ok, this much is true. Even before loading any script, the mod_perl
module will cost you quite a bit in RAM. I recently compared Apache
1.3.6 httpd on FreeBSD 2.2.8 with and without mod_perl. The difference
in memory space after the httpd is started up is about 800kb-1MB. In
fact, the requirement PER PROCESS increased about 300% (ie 3x)! This
is quite major considering that an ISP would normally pre-fork about 15-
25 processes and keep about 10-15 spare processes around.
> 2) A lot of scripts use global variables. Since there is effectively
> only one copy of Perl running, any global variables set by a script
> are available to other scripts and scripts that don't bother
> initialising their global variables will start off with the wrong
> values.
Quite close to what I read in the mod_perl docs (I may be mistaken
thought). However, with proper use of my(), this should be reduced.
> 3) Configuration. It is actually quite difficult to set this up to
> work efficiently.
Compilation is a bear. Configuratiion is tricky (for the less
experienced). However, it only needs to be done once.
> 4) Development. Because a script is cached by the process you cannot
> simply upload a new version and expect Apache to serve it correctly. I
> think you have to either restart the Apache process or send it a
> signal that causes it to flush the cache.
Not sure... I usually "bounce" the server when I develope them.
> 5) Reliability. mod_perl is really designed for fairly static CGI
> servers where the scripts are tested thoroughly before being available
> via the enhanced server. It is possible for badly written scripts to
> interfere with other scripts and even cause the Apache process to
> crash. This would be a nightmare for the System Adminstrators.
True.
> Are these criticisms valid? If so are they also true of Java Servlets
> and Java Server Pages? Is mod_perl a viable facility for ISP's to
> supply to subscriber's homepages or is it more suited to Corporate
> Intranets or larger web sites running their own servers?
For Java servlets, issue 1) is present but in a different way. The
mod_jserv module is pretty small. However, that is not where the
actions and processing takes place. In J-servlets, the mod_jserv just
redirects HTTP requests to the (single) JVM that is started when you
start up Apache. The JVM itself is the memory hog. Depending on your
servlet, you can use up a lot more memory than mod_perl. 2) is not an
issue for J-servlet. 3) is easier to setup (for me) as I already have
some example while I approached mod_perl fresh. YMMV. 4)
Theoratically, jserv allows dynamic loading/reloading, but I've not
played with it extensively to go either way. 5) You can write bad J-
servlets too.
Watcher
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 23 Jun 1999 03:15:06 GMT
From: brad.kruse@pobox.com
Subject: Re: Newbie - Perl books - which to get?
Message-Id: <7kpjfj$rc1$1@nnrp1.deja.com>
In article <B3956F4E966812BAF3@204.112.166.88>,
rlb@intrinsix.ca (Lee) wrote:
> >Hi All,
> >I looked on Amazon for Perl books and found quite a few. I would
like
> >to order a couple. Here is my narrowed list:
> >
...
> >Advanced Level -
> >Effective Perl Programming: Writing Better Programs with Perl -
Joseph
> >N. Hall
> >Programming Perl (2nd Edition) - Larry Wall
...
>
> 3) Learning/Programming Perl are excellent books. Add The Perl
Cookbook to
> the list, and you probably have everything you'll ever need.
...
>
> 5) I think that second heading should read "Intermediate." There are a
few
> advanced books if you aspire to guru status.
>
> Lee
I agree. I started with the Programming Perl, then the Advanced Perl
Programming which explained a lot about minor topics that I hadn't
realized would help, like references and modules. This is VERY important
in advancing past the initial 'competent' level of Perl. The Perl
Cookbook was great value for the cost, but not my most-used reference.
Effective Perl Programming, Hall & Schwartz, is an absolute delight.
The book exlains and coaxes me to understand and use various features of
Perl 'better'. I found that the first 50 pages were fascinating,
entertaining, and even better -- reduced the number of errors in the
scripts I write. I think that this book is definitely for the
programmer wanting that next level after beginner. Perl Programming and
a couple months of scripting should be sufficient preparation.
Enjoy!
Brad K.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 22 Jun 1999 23:37:54 -0400
From: "Andy" <ranaylor@cais.net>
Subject: Re: Newbie - Perl books - which to get?
Message-Id: <QCYb3.153$Sw3.3300311@newsie.cais.net>
How about for win32 systems?
I've already purchased the Lizard book.
Any comments on this one. It's still being shipped as of this message.
Andy...
Eric Bohlman wrote in message ...
>David Cassell (cassell@mail.cor.epa.gov) wrote:
>:
>: > Advanced Level -
>: > Effective Perl Programming: Writing Better Programs with Perl - Joseph
>: > N. Hall
>: > Programming Perl (2nd Edition) - Larry Wall
>:
<snip>
------------------------------
Date: Wed, 23 Jun 1999 04:09:20 GMT
From: chitown34@my-deja.com
Subject: Perl and Personal Web Server (Win98)
Message-Id: <7kpmla$sag$1@nnrp1.deja.com>
I'm trying to configure ActivePerl for use with
Microsoft's Personal Web Server on a Windows98.
I installed PWS and ActivePerl.
There is a mention of changing some registry
settings in the documentation, but I am hesitant
because I am unfamiliar with registy info and I
don't want to screw anything up.
Could someone provide me step by step instructions
for modifying the registry as required by the
documentation?
Thanks.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 22 Jun 1999 18:01:15 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl equivalent of #INCLUDE?
Message-Id: <b31pk7.f21.ln@magna.metronet.com>
Ron Ginger (ginger@ma.ultranet.com) wrote:
: Im doing several perl programs. I have a set of common subroutines I
^^
: want to use in them so I want to put the common stuff into a separate
: file for easy maintenance. But, I want the subs to be able to use the
: global vars Ive defined in my main routines. If I 'use' or 'require' the
^^^^^^^^^^^
Let's see the code that defines them.
[ is your single quote key broken or something? ]
: subroutine file the subs do not see my global vars.
sub some_module_sub {
print "the global \$foobar variable's value is $main::foobar\n";
}
: Ive read lots of the stuff on building modules, but it all seems to be
^^^
: involved in hiding the subs vars from the main program, or selectively
^^^^
: exporting them. I cant find anything that talks about a sub using the
^^^^
: mains globals.
^^^^^
Sheesh!
Why put obstacles to understanding in your article?
That seems counterproductive...
: I know that a sub defined in the main routine can see the vars as
: global. I really want a simple #INCLUDE ability
^^^^^^^^
Do you mean #include, like in C?
I don't know of any languages that have a #INCLUDE ability.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 23 Jun 1999 00:23:26 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Piping through Less.
Message-Id: <1dttr96.1oro2g3rz7rl7N@p15.tc5.metro.ma.tiac.com>
ktb <xyf@inetnebr.com> wrote:
> The result of this is the same as the other. Only one line gets read
> into 'less' How can I get all lines to read into 'less'?
Did you try printing more than one line?
[Hint: open() and close() the pipe *outside* the loop.]
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 23 Jun 1999 00:23:27 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <1dttrq6.1npzvuy1u9as7dN@p15.tc5.metro.ma.tiac.com>
Bart Lateur <bart.lateur@skynet.be> wrote:
> * Check the most frequent occuring prefix in one post, excluding
> whitespace. Something like:
>
> while(/^(\S\S)/gm) {
> $prefix{$1}++;
> }
>
> * The number of quoted lines is the highest value in values %prefix. Or,
> sort keys %prefix acooording to value, and pick the last item.
>
> The only way to beat that, is to use more than one quoting prefix in one
> post, which *definitely* is bad Usenet prectise, and qhould be frowned
> upon, as it will no longer be easily identifiable as quoting, for the
> human reader, also.
If you think that's the only way to beat that heuristic, then I'm afraid
you're not being very imaginative. (And that's on top of being
inordinately obsessed with this issue in the first place!)
~ Abigail could use a single non-whitespace character followed by
~ whitespace, like this.
Abigail could just indent the quoted text, without using any
non-whitespace characters at all, like this.
@@ Abigail could use whatever quote characters she wants for
@@ for the actual quoted text, but then spoof the counting with
@@ empty lines using other quote characters, like this.
^^
^^
^^
^^
--- quoted text ---
Abigail could prefix and suffix blocks of quoted text with quote
markers, like this.
--- end quoted text ---
Give up yet?
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 23 Jun 1999 02:44:57 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Summing an array
Message-Id: <7kphn8$kuq$1@monet.op.net>
In article <x7pv2o6l7m.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "JS" == James Stewart <james@britlinks.co.uk> writes:
> >> I guess I could do it with
> >> a loop, but I'm guessing there's a more elegant solution.
>
>can't get much simpler (except in apl where it is "SUM<-ARRAY/+" IIR)
Close. In APL it's
sum <- +/ array
But regardless, there's still a loop. There *has* to be a loop. The
only question is whether you can see it or not.
------------------------------
Date: 22 Jun 1999 23:53:02 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Summing an array
Message-Id: <x7k8sv7eu9.fsf@home.sysarch.com>
>>>>> "MD" == Mark-Jason Dominus <mjd@op.net> writes:
MD> In article <x7pv2o6l7m.fsf@home.sysarch.com>,
MD> Uri Guttman <uri@sysarch.com> wrote:
>>>>>>> "JS" == James Stewart <james@britlinks.co.uk> writes:
>> >> I guess I could do it with
>> >> a loop, but I'm guessing there's a more elegant solution.
>>
>> can't get much simpler (except in apl where it is "SUM<-ARRAY/+" IIR)
MD> Close. In APL it's
MD> sum <- +/ array
very, very, rusty. so why did you set followups to c.l.apl?
cu at yapc.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 22 Jun 1999 21:53:51 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Summing an array
Message-Id: <ylbte7h600.fsf@windlord.stanford.edu>
Mark-Jason Dominus <mjd@op.net> writes:
> Close. In APL it's
> sum <- +/ array
> But regardless, there's still a loop. There *has* to be a loop. The
> only question is whether you can see it or not.
Not *necessarily*, although yes I'd expect it to be in most applications.
One of the data structures that I've implemented in the past (in C) had as
its requirements O(lg N) insert time and O(lg N) item to get the sum of
all elements from the beginning of the structure to that specific element.
(It also required preservation of order, traversal, and scaling to
arbitrary sizes without knowing the size in advance, so hash tables would
have been very painful.)
We implemented it as a skip list that stored partial sums at all of the
nodes of height > 1, so as you followed the lookup path for a particular
element, you could get the sum for essentially free.
You could do something similar with an array; the most trivial
implementation would be to store a full sum with each element. Of course,
if you need sums from the beginning of the list to an arbitrary element
with O(1) retrieval, you end up with O(n) insertion times.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Wed, 23 Jun 1999 02:15:25 GMT
From: Mitch <portboy@home.com>
Subject: Timing out problem...Suggestions?
Message-Id: <376FD35C.DC6A2737@home.com>
Okay, when my script start up, it provides you with a prompt requiring
you to enter your password. Assuming the password is valid, it then
sends you to a command prompt. prompt> What I'm to do is, if they
are at the prompt for say 5 seconds, and they haven't entered
anything...I want to call a subroutine that will log them out. When
they are logged out, they are returned back to my password prompt
where it can sit there for forever.
I've been trying to work from the example shown in the Perl Cookbook,
and it works to some degree, but I'm still having trouble. The
trouble is, when they get to the "prompt>" it will sit there for five
seconds and then log the user out, however, when I try to type a
command at my "prompt>" it immediately exits the script. Can someone
explain to me why this is happening?
Here's the jist of my code:
$SIG{ALRM} = sub { die "timeout" };
sub commands {
while (1)
{
&timer; # The commented lines below is how I used to
show the prompt. the &out subroutine is nothing more than a "print
shift" statement.
# ($delta == 1) {
#&out(&prompt2);
#} else {
#&out(&prompt);
#}
#my($an) = &get_line;
#($cmd, @args) = split(/\s+/, $an);
# all lines below here at nothing more than a call to
the various command subroutines.
&{$command{sub}}(@args);
}
}
sub timer
{
eval {
alarm(5);
if ($delta == 1) {
&show(&prompt2);
} else {
&show(&prompt);
}
my ($an) = &get_line;
($cmd, @args) = split(/\s+/, $an);
alarm(0);
};
if ($@ =~ /timeout/) {
&logout; # returns the user to the password prompt.
} else {
alarm(0);
die;
}
}
So, what am I doing wrong?
------------------------------
Date: 22 Jun 1999 21:22:43 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: To obfuscate or not?
Message-Id: <ylhfnzh7fw.fsf@windlord.stanford.edu>
Carey Barnett <cbarnett@idirect.com> writes:
> I've noticed posts to newbies with code that is not as readable as it
> could be. Some of it is downright cryptic: So... should we, or
> shouldn't we?
There's a big difference between terse, cryptic, and obfuscated code.
Obfuscating code is something you do for fun. Like my sig. Obfuscated
code has no place in production applications or in code that's supposed to
be maintainable. It's a hobby, a way of learning more about edge cases in
the language, and something that can just be enjoyable if you're in the
mood.
Cryptic code should be avoided whenever possible, commented when the
alternatives are even more painful, and should be coded in a style that
makes the code as clear as possible. In other words, I'd consider the
only reasonable crypticness to be cryptic algorithms that are superior to
the alternatives.
Terse code, on the other hand, is more of a style thing. Something like:
print "debug: $_\n" if $debug;
is more terse than:
if ($debug) {
print "debug: $_\n";
}
I personally find the former easier to read because it doesn't waste time
and screen space with irrelevant syntactic clutter. I prefer programming
in a style where every expression is the most straightforward and simple
expression of what I'm trying to say as possible.
I also believe in writing Perl for Perl programmers to read. I don't
believe in writing Perl for people who don't know Perl. So I freely use
map, grep, for loops on the same line (if I don't need backwards
compatibility), and implicit $_. This is part of the language; people who
know Perl won't find this hard to read.
So I like a fairly terse syntax because I think it's more expressive and
easier and faster to read. But that doesn't mean using constructs that
make it difficult for experienced Perl programmers to understand the code.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 22 Jun 1999 22:10:23 -0300
From: "=?iso-8859-1?Q?Fr=E9d=E9rick?= Giasson" <fred@decatomb.com>
Subject: We need you help to find some links, documents, sources codes and with the EMag
Message-Id: <377033FF.68FB3AB0@decatomb.com>
Hello,
We want to expand this information base and to improve our
document
libraries, our links and our newsgroup section. We would like your help
to achieve this. With you, we will be helping a lot of the world's
coders. Our goal is to help you develop cutting edge applications, by
providing the resources you need so you will never give up. (
http://www.decatomb.com/dev/ )
please submit your links, documents, source codes to : dev@decatomb.com
Also, if you have an article for the EMag =
( http://www.decatomb.com/dev/emag.htm ) please send it to :
dev@decatomb.com
Thank's alot for you help
Fr=E9d=E9rick Giasson
Programmer of Decatomb Production
fred@decatomb.com
------------------------------
Date: Wed, 23 Jun 1999 02:39:48 GMT
From: eristic@lodz.pdi.net (marek jedlinski)
Subject: webget, perl 5.005_03 on Linux, cryptic error
Message-Id: <377141ca.23620888@153.19.253.204>
I've been trying to run Jeffrey Friedl's 'webget' on my ISP's shell account
(Linux RH 5.1 on i386). webget runs fine on my win95, but for a reason I
need to run it on the shell account. Well, I only tried once, because this
is what happens: [output wrapped by the newsreader]
[eristic]$ ./webget.pl http://www.lodz.pdi.net/~eristic/index.html
Prototype mismatch: sub main::__need_size_t vs () at (eval 50) line 1.
String found where operator expected at (eval 189) line 1, near "&__const
'struct sockaddr'"
(Missing operator before 'struct sockaddr'?)
Deep recursion on subroutine "main::SOCK_STREAM" at (eval 73) line 1.
At which point webget didn't die and had to be Ctrl-C'ed out of existence.
Now, I know way too little to even think of fixing the problem, but it
looks like some incompatibility at a deep (socket?) level. And of course
the errors do not occur inside webget itself. I understand the "deep
recursion" warning, but 'line 1' in what file? And, really, line ONE?
Is this something that perl 5_005 introduced, or did my ISP perhaps
incorrectly install the new release? "struct sockaddr" is C, not perl...
Thanks a lot for any hints,
.marek jedlinski
--
General Frenetics, Discorporated: http://www.lodz.pdi.net/~eristic/
"So tell me, just how long have you had this feeling that no one is
watching you?" (Christopher Locke: Entropy Gradient Reversals)
------------------------------
Date: 12 Dec 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 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 6102
**************************************