[9486] in Perl-Users-Digest
Perl-Users Digest, Issue: 3081 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 7 12:18:23 1998
Date: Tue, 7 Jul 98 09:01:31 -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, 7 Jul 1998 Volume: 8 Number: 3081
Today's topics:
Re: how long does it take to execute some code? <quednauf@nortel.co.uk>
Re: how long does it take to execute some code? (Larry Rosler)
Re: How to get files in a directory? <jc@ral1.zko.dec.com>
Re: inetinfo sticks in NT (Jeremy D. Zawodny)
Re: Is Perl through CGI enough for this? <jc@ral1.zko.dec.com>
methods to insert/substitute blocks of text? <dtbaker_@flash.net>
Re: methods to insert/substitute blocks of text? <quednauf@nortel.co.uk>
Re: methods to insert/substitute blocks of text? <tchrist@mox.perl.com>
Re: open2 problems (Harold Bamford)
Re: open2 problems <tchrist@mox.perl.com>
Re: Randomize number between -0.5 and 0.5 (Larry Rosler)
Re: Randomize number between -0.5 and 0.5 (Larry Rosler)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Jul 1998 15:18:56 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: how long does it take to execute some code?
Message-Id: <35A22E50.23DFB321@nortel.co.uk>
dwiesel@my-dejanews.com wrote:
>
> How do I find out how long time it takes to execute some code?
>
> // Daniel
use Benchmark;
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: Tue, 7 Jul 1998 08:13:16 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how long does it take to execute some code?
Message-Id: <MPG.100bdaebd4b1706698971c@nntp.hpl.hp.com>
In article <6nt5nb$qp2$1@nnrp1.dejanews.com> on Tue, 07 Jul 1998 12:52:59
GMT, dwiesel@my-dejanews.com <dwiesel@my-dejanews.com> says...
> How do I find out how long time it takes to execute some code?
In addition to the suggested use of Benchmark for isolated snippets or
the Unix time command for entire programs, you can time segments of code
very simply by inserting statements like this:
my $t0 = (times)[0]; # Record starting time.
# Code segment to be timed...
my $t1 = (times)[0]; # Record ending time.
printf "%.2f\n", $t1 - $t0; # The difference is in seconds.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 07 Jul 1998 11:46:50 -0400
From: John Chambers <jc@ral1.zko.dec.com>
Subject: Re: How to get files in a directory?
Message-Id: <35A242EA.53C33394@ral1.zko.dec.com>
brian d foy wrote:
>
> In article <359BAB97.9CCFC665@perrier.bmc.uu.se>, m94tne@student.tdb.uu.se posted:
>
> >What is the command for getting (all) files (as a list) in the current
> >directory?
>
> perldoc -f opendir
>
> then
>
> perldoc perlfaq
>
> good luck :)
>
> --
> brian d foy <comdog@computerdog.com>
> CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
> Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
> Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>
Jeez, why didn't anyone even mention the much simpler solution:
@files = glob("*");
Not that there's anything wrong with opendir and readdir, and you
probably do want to know about them in case you want to do something
more complicated than just get a list of the files. But the fellow
just wanted to know what files were in the directory. You'd think
that glob would at least deserve a mention.
(Of course, glob("*") doesn't show you the hidden files.)
------------------------------
Date: Tue, 07 Jul 1998 15:03:16 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: inetinfo sticks in NT
Message-Id: <35a23895.7102092@192.70.218.1>
[original author automagically cc'd via e-mail]
On Tue, 7 Jul 1998 11:04:41 +0300, "Antti Boman"
<antti.boman***SP@MPROTECTION***mindcom.fi> wrote:
>>Like that... my task manager shows the task "inetinfo" using 100%
>>resources, and I cannot end-task it.
>
>Even if this is not a perl question, it's worth answering (if someone having
>the same problem happened to check the archives).
>
>I've used the dirty trick by using Reskit's tlist and kill. First get the
>PID with tlist and murder her! :) Then start again.
Shouldn't be necessary. kill will take a program name as an argument.
Jeremy
--
Jeremy D. Zawodny jzawodn@wcnet.org
Web Server Administrator www@wcnet.org
Wood County Free Net (Ohio) http://www.wcnet.org/
------------------------------
Date: Tue, 07 Jul 1998 11:28:46 -0400
From: John Chambers <jc@ral1.zko.dec.com>
Subject: Re: Is Perl through CGI enough for this?
Message-Id: <35A23EAE.DAACB574@ral1.zko.dec.com>
David Rouse wrote:
> I had thought to run the system using Filemaker, but I've been given a Sun
> server to run the system on. So I've bought O'Reilly's "Learning Perl,"
> and started lurking on this group. I'm thinking now of running the system
> using web browsers on the clients and perl scripts, dbm (or something) and
> apache on the server.
>
> Will that combination be enough? Is it possible to build a system that
> will be robust enough to work correctly? If someone fills in a browser
> form that orders a full page ad for a certain day -- and that ad doesn't
> get manifested -- the company would be loosing thousands of dollars.
It should be fine for the job. But you do have a bit of work ahead of
you. You might do a bit of research to see if someone has built and is
marketing such a system already. (Then you'd have the problem of trying
to get their software to work right, rather than writing it yourself. ;-)
The hard part of such a system is the software for building the ads, and
if you want that to be part of your web pages, you have a major project
ahead. But if you already have a system for building the ads, and all
you need to do is handle the scheduling, it's probably pretty easy to
write CGI scripts to do the job. The two critical parts that you want
to get answers to right away are: 1) How does a script get the list of
ads that are available? 2) How does a script schedule an ad to be run?
These questions have nothing to do with the web, of course, and if you
can get little sample programs that do these jobs as standalone commands,
writing the ad list to stdout in case 1 and accepting a new schedule item
from command line args or stdin in case 2, then the rest is straightforward.
Wrapping these in html isn't a big deal, and you probably do want to do
it yourself. Using someone else's commercial product to do them will mean
digging into their code and figuring out why things have gone wrong. If
you write your own CGI scripts to glue the pieces together, then you'll
know what's going on, you can write your own audit trails, and so on.
Making web-based things robust mostly means producing the log files and
audit trails so you can easily verify everything.
If this is your first web project, you're in for a learning experience ...
Oh, yes; if your "database" is really a database (and not just files in
a directory), you'll want to check out the perl DB module at your local
CPAN site. Database access gets tricky in any language. The perl DB
guys have ironed out a lot of the problems and can tell you a lot about
accessing databases from CGI script.
------------------------------
Date: Tue, 07 Jul 1998 09:43:11 -0500
From: Dan Baker <dtbaker_@flash.net>
Subject: methods to insert/substitute blocks of text?
Message-Id: <35A233FF.7080@flash.net>
I would like to get some thoughts from the crowd on different methods to
substitute blocks of text into templates. I have "surfed" up a couple
posts mentioning this sort of functionality in a couple different
modules, but have not tested to see which one is the easiest to
implement.... I'd like to hear from some people who have done this type
of thing. It would be great if some discussion got started that could
compare and contrast the available methods.... as long as it doesn't
become a religious war. ;)
The project is to substitute small chunks of dynamically generated text
into largely static HTML source. i.e. create drop-down choice lists
dynamically.
I'd *like* to leave the HTML source page as working source so that
non-perl people can edit the basic format of the page (as long as they
don't delete start/end tags or whatever is required for substitutions.
Please let me know what modules you think would be best for this sort of
substitution work! Also, if you have any simple examples, or tutorial
type material online, let me know!
thanx,
Dan
------------------------------
Date: Tue, 07 Jul 1998 16:15:22 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: methods to insert/substitute blocks of text?
Message-Id: <35A23B8A.ACCE5C12@nortel.co.uk>
Dan Baker wrote:
>
> I would like to get some thoughts from the crowd on different methods to
> substitute blocks of text into templates.
There must be s...loads of different ways to do this.
On my webpage there is a script which has the static webstuff stored in the
__DATA__ entry of the script. It then outputs that together with some
dynamically generated stuff in the middle. Handy if you want everything to be
together! Check it out through my sig!
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: 7 Jul 1998 15:53:15 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: methods to insert/substitute blocks of text?
Message-Id: <6ntg9b$s6i$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
dtbaker_@flash.net writes:
:I would like to get some thoughts from the crowd on different methods to
:substitute blocks of text into templates.
>From the Perl Cookbook:
To expand only variable references, use this template() function:
%fields = (
username => $whats_his_name,
count => $login_count,
total => $minute_used,
);
print template("/home/httpd/templates/simple.template", \%fields);
sub template {
my ($filename, $fillings) = @_;
my $text;
local $/; # slurp mode (undef)
local *F; # create local filehandle
open(F, "< $filename") || return;
$text = <F>; # read whole file
close(F); # ignore retval
# replace quoted words with value in %$fillings hash
$text =~ s{ %% ( .*? ) %% }
{ exists( $fillings->{$1} )
? $fillings->{$1}
: ""
}gsex;
return $text;
}
On a data file like this
<!-- simple.template for internal template() function -->
<HTML><HEAD><TITLE>Report for %%username%%</TITLE></HEAD>
<BODY><H1>Report for %%username%%</H1>
%%username%% logged in %%count%% times, for a total of %%total%% minutes.
--tom
--
The human mind ordinarily operates at only ten percent of its capacity
--the rest is overhead for the operating system.
------------------------------
Date: 7 Jul 1998 15:10:06 GMT
From: hbamford@marconi.ih.lucent.com (Harold Bamford)
Subject: Re: open2 problems
Message-Id: <6ntdoe$3no@ssbunews.ih.lucent.com>
In article <gvl4swt28lg.fsf@eto.ericsson.se>,
=?ISO-8859-1?Q?B=F8rre_Fjelds=F8?= <Borre.Fjeldso@ericsson.no> wrote:
>NEVER EVER fix a script after you paste it into a message <sigh>, hope
>this supersede catches it...
Why?
In any case, this seems to work well. Thanks. However, I really don't
understand what the critical change was. Clearly the script is not
hanging on the read anymore (due to checking with select), but I would
THINK that this shouldn't be necessary -- 'cat -u' is supposed to
output immediately. Obviously not. But it does when I use it
interactively. Can anybody explain what is happening here?
> if ($sel->can_read($RDR)) {
> my $line = <$RDR>;
> print "got back: $line";
> }
Thanks again.
-- Harold
BTW, this was a contrived example which is why I wasn't counting input
or output lines, or checking on open2's success or any of the other
normal good programming stuff. Perhaps a full working example of open2
and open3 should be put in the documentation. Sure would have saved me!
--
-- Harold Bamford
mailto:hbamford@lucent.com
(630)713-1351
------------------------------
Date: 7 Jul 1998 15:50:05 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: open2 problems
Message-Id: <6ntg3d$s6i$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, hbamford@lucent.com writes:
:Perhaps a full working example of open2
:and open3 should be put in the documentation. Sure would have saved me!
You mean the one in perlipc, which I just tested and which works?
use IPC::Open2;
$pid = open2( \*Reader, \*Writer, "cat -u -n" );
print Writer "stuff\n";
$got = <Reader>;
print "Got $got\n";
--tom
--
You have made an excellent hit on the UNIX.--More--
------------------------------
Date: Tue, 7 Jul 1998 08:51:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Randomize number between -0.5 and 0.5
Message-Id: <MPG.100be3cb785560b498971e@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <35a217e0.3503205@news.tm.net.my> on Tue, 07 Jul 1998 12:43:50
GMT, Huang <wong2020@tm.net.my> says...
...
> If I repeat and run again the programme, the output will be the same.
> I wish to have all random value. And when I run next time, I wish to
> see a set of random value again.
>
> Am I misplace my srand () ??
If your perl is 5.004, you don't need to call it at all. If 5.003, you
can call it exactly once before the first use of rand(), without an
argument or (required for 5.002) with a different argument for each
execution.
The incantation I use (including the "do this once only" trick I learned
recently) is:
srand($^T ^ ($$ + ($$ << 15))) if $] < 5.004 && 1 =~ ?1?;
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 7 Jul 1998 08:45:31 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Randomize number between -0.5 and 0.5
Message-Id: <MPG.100be2736c24957698971d@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <35a217e0.3503205@news.tm.net.my> on Tue, 07 Jul 1998 12:43:50
GMT, Huang <wong2020@tm.net.my> says...
...
> If I repeat and run again the programme, the output will be the same.
> I wish to have all random value. And when I run next time, I wish to
> see a set of random value again.
>
> Am I misplace my srand () ??
If your perl is 5.004, you don't need to call it at all. If 5.003, you
can call it exactly once before the first use of rand(), without an
argument or (required for 5.002) with a different argument for each
execution.
The incantation I use (including the "do this once only" trick I learned
recently) is:
srand($^T + ($$ + ($$ << 15))) if $] < 5.004 && 1 =~ ?1?;
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 3081
**************************************