[9008] in Perl-Users-Digest
Perl-Users Digest, Issue: 2627 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 18 12:08:15 1998
Date: Mon, 18 May 98 09:01:48 -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 Mon, 18 May 1998 Volume: 8 Number: 2627
Today's topics:
Re: memory efficiency question <jari.aalto@poboxes.com>
Need a Perl Data Processing Example <rrayborn@slip.net>
Re: New IDE for Perl (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
Re: Nuclear bombing of NEW YORK! Small countries can ta <keithmur@mindspring.com>
On nt, How to invoke perl script as cgi program using a <hyang@flash.net>
Re: Perl Script for System Backup? - 2 Questions (Gabor)
Re: Playing with PostgreSQL <swood@TheWild.Com>
Please help understand $| <yong@shell.com>
Re: POP UP window scott@softbase.com
regexp: replacing new line followed by "+" <r29173@email.sps.mot.com>
test (c)
Tied Filehandle calls FETCH?! (was: Tip: Filehandles) (Steffen Beyer)
Timing a script <andrew@ctec.org.uk>
Re: uniq in perl <swood@TheWild.Com>
Re: uniq in perl johnvv@hotmail.com
Re: vec basics (Steffen Beyer)
Re: while, each & assoc array <jll@skynet.be>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 May 1998 18:54:31 +0300
From: Jari Aalto <jari.aalto@poboxes.com>
Subject: Re: memory efficiency question
Message-Id: <ptrg1i7h8w8.fsf@uta.fi>
|Thu 98-05-14 Brandon Golm <br@ndon.com> comp.lang.perl.misc
|
| > | You'd better benchmark that! I assumed the same thing and found that line
| > | at a time was somewhat faster than loading into an array!
| > |Reading the whole
| > | file into a scalar, however, was very fast...
|
| {
| local $/ = undef;
| $file = <FILE>;
| }
I can't see the boost? Is my benchmark somehow faulty? The test file was
roughly 100k. Perl 5.4_4 HP_UX 9000/712 10.20
jari
use Benchmark;
timethese( 10000,
{
a =>
'open F, "test.txt"; @file = <F>; close F'
,
b =>
'$/ = undef;
open F, "test.txt"; @file = split /\n/,<F>; close F'
,
c =>
'$/ = undef;
open F, "test.txt"; $file = <F>; close F'
});
a: 16 secs ( 2.37 usr 5.37 sys = 7.74 cpu)
b: 16 secs ( 2.77 usr 5.49 sys = 8.26 cpu)
c: 16 secs ( 2.14 usr 5.39 sys = 7.53 cpu)
------------------------------
Date: Mon, 18 May 1998 06:27:13 -0700
From: "Randal Rayborn" <rrayborn@slip.net>
Subject: Need a Perl Data Processing Example
Message-Id: <6jpcj1$1gi$1@owl.slip.net>
I have two fixed field data files which I need to read in, join together on
a merge key (say one for simplicity) and write out as a complete file. Does
anyone have a good code example for this? I am specifically interested in
the process of reading a record from one file then looping through and
matching the key field on the other file. This is a very "COBOL-like"
operation.
Thanks for your help,
Randal Rayborn, MCSE
------------------------------
Date: Mon, 18 May 1998 12:12:45 +0100
From: lassehp@imv.aau.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
Subject: Re: New IDE for Perl
Message-Id: <lassehp-1805981212460001@ra.imv.aau.dk>
In article <6jigp2$m6q$1@ns1.arlut.utexas.edu>, smcdow@arlut.utexas.edu
(Stuart McDow) wrote:
>comdog@computerdog.com (brian d foy) writes:
(Stuff about ed deleted)
>(Let's see how many people take this seriously) :-)
When I began using Unix (A/UX, terminal-based: we killed the Macintosh
processes to save CPU-cycles) I wrote several small programs (shell or C,
but not perl at the time) with ed. Ed really has all you need, and is
simple to use. Which was my main reason for using it: I didn't feel like
learning vi at the time - for large texts I used MPW or Alpha on the Mac):
You have all the necessary commands and then some, here is enough ed to do
something useful:
1,10p -- show lines 1,10
.,$p -- show from the current line to last line.
.s/ed sucks/ed is cool/ -- replacement
10a -- append after tenth line
. -- stop typing text or print current line if not typing text.
$d -- delete last line
w -- write
q -- quit
Ed makes more sense than either vi or EMACS, really it does. And I _am_
serious! (I *still* can't remember what the code is to get out of EMACS,
except ^Z and a kill; at least ESC :q makes _some_ sense)
If only ed was 8-bit compatible and had no limit on file size, I guess I'd
still be using it! (Now I use vi, and try vim once in a while. Most of the
time I just mount my Unix directories on the Mac and use BBEdit.)
Here is a small suggestion for a contest: write an ed clone in Perl,
without resorting to a shell escape (except for the ! command, of course).
-Lasse
--
No documentation found for "perlsex".
------------------------------
Date: Mon, 18 May 1998 11:00:15 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Nuclear bombing of NEW YORK! Small countries can target with nukes!
Message-Id: <35605B0F.D70BEF32@mindspring.com>
Rosemary I H Powell wrote:
>
> In article <MPG.fc3b015e85172449896b5@news.min.net>, John Porter
> <jdporter@min.net> writes
> >> You are living, sleeping and walking on a planet which is a
> >> LIVE ATOM BOMB and a HUGE BAR MAGNET!!
> >
> >The LIVE ATOM BOMB part is spooky, but the HUGE BAR MAGNET part totally
> >scares the sh*t out of me. What can we do, who can we call?
> >
> >John Porter
> But John, FEAR NOT! If it wasn't for the planet being a HUGE BAR MAGNET,
> we'd all go flying off into space, and not be able to read clpm any
> more....
Have you ever noticed that all those little grommets where your
shoelaces go in are made of *METAL*? Coincidence? I think not. I for
one, will never again risk walking barefooted outside.
------------------------------
Date: Mon, 18 May 1998 08:33:55 -0700
From: "James" <hyang@flash.net>
Subject: On nt, How to invoke perl script as cgi program using apache?
Message-Id: <6jpkil$8c5$1@excalibur.flash.net>
Hello,
On nt, how to invoke perl script as cgi program using apache?
For example,
I want to run a program
printenv.pl xy
through CGI,
but a form always build everything in to name=value pair.
so a form build the following cgi request
http://sailor/cgi-bin/perl?printenv.pl=xy
which does not work.
What I am doing wrong?
Thanks in advance
James
------------------------------
Date: 18 May 1998 13:09:26 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Perl Script for System Backup? - 2 Questions
Message-Id: <slrn6m0d4k.5so.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, Phil Houstoun <phousto@cse.dnd.ca> wrote :
# Authorized User wrote:
# >
# > I want a flexible and powerful script to backup selected
# > files on a WinNT system.
# > Rexx and Batch files are one answer. Is there an advantage to Perl?
# > By the way, as I play with this idea it perplexes me that the Llama book
# > in chapter 13 describes renaming and deleting, but not copying files.
# >
# > I looked in the Win32 release documentation and found Win32 extensions
# > that permit chdir, pwd,...equivalents, so indeed I can delete , rename,..,
# > but can't find out how to copy.
#
# use File::Copy;
# copy($infile, $outfile);
Or
use File::NCopy;
File::NCopy::copy(\1,$dir,$dirto);
will recursively copy $dir into $dirto
or if you only wnat the files under $dir copied, includng the dirs
File::NCopy::copy(\1,"$dir/*",$dirto);
you can also use File::NCopy as an object oriented class, in fact
internally it always functions as one.
------------------------------
Date: Mon, 18 May 1998 11:37:31 -0400
From: Scott Webster Wood - TheWild Webster <swood@TheWild.Com>
Subject: Re: Playing with PostgreSQL
Message-Id: <Pine.LNX.3.96.980518113521.12717D-100000@tre.thewild.com>
Does anyone have a copy of this article?
If an when this month does come up, do you recall the subject line? Last
months has a lot of stuff with DBI and PERL in the subject lines.
Scott
On 16 May 1998, Leslie Mikesell wrote:
> In article <Pine.LNX.3.96.980514143222.20109D-100000@tre.thewild.com>,
> Scott Webster Wood - TheWild Webster <swood@TheWild.Com> wrote:
> >I have been trying to compare/contrast various SQL packages for perl. I
> >have since installed the mSQL and the PostgreSQL stuff on various boxes
> >for testing. I have found a couple of routines for Perl to talk to them,
> >but the only ones that I have found thus far (at least at first glance)
> >utilize an expr routine or something similar to send commands to and from
> >the SQL server. I was kinda hoping that something would allow me to
> >create objects that would match the object databases I wanted to create in
> >the SQL.
>
> There was a recent posting to the DBI mailing list that had some
> utility functions to convert between perl hashes and sql columns.
> The list is archived at http://outside.organic.com/mail-archives/dbi-users/
> but the current month doesn't seem to be working yet.
>
> Les Mikesell
> les@mcs.com
>
>
------------------------------
Date: Mon, 18 May 1998 10:52:56 -0500
From: Yong Huang <yong@shell.com>
Subject: Please help understand $|
Message-Id: <35605957.E2191721@shell.com>
In Programming Perl (2nd ed), p.130, it says "Contrary to popular
belief, setting this variable [$|] does not turn off buffering". Can
somebody explain (sample code would be best)? Or tell me how to turn off
buffering if possible at all or if indeed necessary in some cases? Isn't
flushing every "print"ed string immediately called "buffer is turned
off"? Is it better to say
use FileHandle;
STDOUT->autoflush(1); #page 211
and why? Thank you for help.
Yong Huang
Email:yong@shell.com
------------------------------
Date: 18 May 1998 10:50:24 GMT
From: scott@softbase.com
Subject: Re: POP UP window
Message-Id: <6jp3pg$89f$4@mainsrv.main.nc.us>
Kira Kira (kira98_98@yahoo.com) wrote:
> I have a HTML form. When a user click on the OK button, I would like to
> see a POP UP window display. But i do not want the current HTML form to
> disappear.
> I know In JAVAscript you can use the "alert()" command. But because i am
> using cgi , you need the "content-type:text/html".
> Please help!!!
You will have to write a JavaScript wrapper around your submit button
that will submit the form automatically and then pop up the window.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: Mon, 18 May 1998 17:24:44 +0200
From: "Lemaitre, Laurent" <r29173@email.sps.mot.com>
Subject: regexp: replacing new line followed by "+"
Message-Id: <356052BC.670E@email.sps.mot.com>
Hello,
In a text file I want to replace a newline by a space
only when the newline is followed by a +.
For example:
=======================
My first line My first line + end of my
first line
+ end of my first line -->
=======================
I tried different options (/s,/m/ and so on) but all failed.
Can somebody help me?
Thanks,
--
Laurent Lemaitre
ASTL/Advanced Circuit Research Lab - Europe Tel: +41 22 799 1371
Motorola Semiconductor Products Sector Fax: +41 22 799 1304
Geneva, Switzerland r29173@email.sps.mot.com
------------------------------
Date: Mon, 18 May 1998 16:34:48 +0200
From: "lo(c)co" <locco@iname.com>
Subject: test
Message-Id: <35604708.1BC2@iname.com>
test
<a href= a@b.c>test</a>
------------------------------
Date: 18 May 1998 14:06:49 GMT
From: sb@engelschall.com (Steffen Beyer)
Subject: Tied Filehandle calls FETCH?! (was: Tip: Filehandles)
Message-Id: <6jpf9p$j7n$1@en1.engelschall.com>
Martin Gregory <mgregory@asc.sps.mot.com> wrote:
> Advanced Perl Programming (an excellent book, which I have only just
> now read, and has the first good documentation I've found on
> typeglobs [...]
I got the book last saturday (i.e., before yesterday), and thanks to it I was
finally (after struggling so hard with all this last year) able to solve the
problem how to make an object which behaves exactly as a file handle *AT
THE SAME TIME*.
It's really a great book, this is exactly what I've always wanted!!
But one weird thing occurs with tied filehandles:
I create my object as follows:
no strict "refs";
$name = $Class . '::LOCATION' . ++$Count;
$inner = \*{$name}; ## creates IO slot entry in typeglob
bless($inner, $Class); ## bless typeglob ref into object
${$name} = $inner; ## save object ref in $ slot of typeglob
tie(*{$name}, $Class, $inner); ## tie filehandle (IO slot) to glob ref
use strict "refs";
And I fill it with data as follows:
$$$inner{'file'} = $file; ## this uses the % slot of typeglob
$$$inner{'data'} = [ ];
$$$inner{'outer'} = { };
$$$inner{'inner'} = { };
$$$inner{'top'} = 0;
The weird thing is that the construct $$inner calls FETCH, which isn't even
a documented method in connection with tied filehandles!
Anyone an explanation why this happens?
The purpose is to be able to say
print $FH "Hello, World!\n";
as well as
$FH->print("Hello, World!\n");
(where $FH would be the "$inner" from above).
For this, there is a method PRINT which is aliased to "print" (via globs)
in that module.
I use the following TIEHANDLE and FETCH functions (and all works well):
sub TIEHANDLE
{
return $_[1];
}
sub FETCH
{
return $_[0];
}
I'd be glad to receive any hints or insights!
Yours,
--
Steffen Beyer <sb@engelschall.com>
Free Perl and C Software for Download: www.engelschall.com/u/sb/download/
"Perl is like sex: If you never had it, you wonder what the fuss is all
about. Once you had it, you never want to be without it again." (unknown)
------------------------------
Date: Mon, 18 May 1998 16:51:31 +0100
From: Andrew Hearn <andrew@ctec.org.uk>
Subject: Timing a script
Message-Id: <35605903.B001702A@ctec.org.uk>
Hi!
Can any one tell me how I can get the time the script takes to run?
EG. in a search script, the script searches and returns the result with
the time it took.
Please mail to the NG and my email, as I don't always have the time to
check the group
Thank you.
Andrew@ctec.org.uk
------------------------------
Date: Mon, 18 May 1998 11:32:32 -0400
From: Scott Webster Wood - TheWild Webster <swood@TheWild.Com>
Subject: Re: uniq in perl
Message-Id: <Pine.LNX.3.96.980518112420.12717B-100000@tre.thewild.com>
I have a short 'uniq' like routine that I wrote for a script at one point.
Kinda short and sweet, nothing fancy, but it works. It works best, of
course (like the unix uniq) if the list was sorted first, but can also be
used to take out repetitive entries in a non-sorted list.
#!/usr/bin/perl
sub uniq { # simple unix like uniq routine
local ($i, @arr);
@arr = @_; # @arr is the list sent to the routine
for ( $i=1; $i<@arr; $i++) { # start at '1' (second list value)
if (@arr[$i] eq @arr[$i-1]) { # check against previous entry
splice(@arr,$i-1,1); # remove if $arr[$i] eq $arr[$i-1]
$i--; # decrement $i to check again on next
}
}
return @arr; # return finished list w/duplicate entries removed
}
I added some comments just to clear up what it was doing...
Scott
--
NOTICE TO BULK E-MAILERS:
Pursuant to US code, Title 47, Chapter 5, Subchapter II, 227;
any and all non-solicited commercial E-mail sent to this address is
subject to a download and archival fee in the amount of $50.
Sending such non-solicited email(s) to this address or any other
address(es) at TheWild.Com without a specific request for said
messages denotes acceptance of these terms.
Furthermore, all materials originating from TheWild.Com and / or
Webster Internet Services are the sole intellectual property of
Scott Webster Wood, Webster Internet Services and their customers.
Any distribution, publication or other replication in any other manner
of such information (including all email addresses, user names or
other resources on TheWild.Com systems) without expressed permission
from Webster Internet Services is forbidden. (and may be in violation
of copyright and/or trademark law where applicable)
TheWild.Com is a commercial (.com) web site - NOT a sales floor. Save
your time, our time, your resources and our resources and DO NOT include
TheWild.Com addresses in your mass mailing lists!!!
--
Scott Webster Wood Webster Internet Services
SWood@TheWild.Com Home of TheWild Web homepage
(313) 913-5511 http://WWW.TheWild.Com
>>> Featuring the Bad Frog Beer homepage and TNUSA of Michigan <<<
On 16 May 1998, Mike Stok wrote:
> In article <td-1605982355270001@mtterror.lavalink.com.au>,
> tony <td@lavalink.com.au> wrote:
> >Hi,
> >I was wondering how to sort a list and output only uniq entries, omitting
> >any multiples. I know how I'd do it from a shell session using awk, sort
> >and uniq:
> >
> >awk -F"\t" '{print $1}' mydatafile.txt | sort |uniq
> >
> >Could anyone tell me how to do it in perl or which man page (section) to
> >be looking at?
>
> perlfaq4 in recent systems has an entry "How can I extract just the unique
> elements of an array?" so you can use split to get the field you're
> interested in. If your data set isn't too big then you might get away
> with building the list of fields in memory before scanning it, otherwise
> you can loop over the input one line at a time, extracting and examining
> the field as you go.
>
> Hope this helps,
>
> Mike
>
> --
> mike@stok.co.uk | The "`Stok' disclaimers" apply.
> http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
> http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
> stok@colltech.com | Collective Technologies (work)
>
>
------------------------------
Date: Mon, 18 May 1998 15:30:36 GMT
From: johnvv@hotmail.com
Subject: Re: uniq in perl
Message-Id: <6jpk6t$cr5$1@nnrp1.dejanews.com>
> awk -F"\t" '{print $1}' mydatafile.txt | sort |uniq
>
> Could anyone tell me how to do it in perl or which man page (section) to
> be looking at?
I think that you almost dont want to since the above stuff works just fine
if you are not sorting a zillion files, except that you can use sort -u
First you do a sort then check for repeats. If you are writing the sort, then
you could make a just in time check which runs as part of the sort routine. I
wrote a sort once...
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 18 May 1998 13:43:05 GMT
From: sb@engelschall.com (Steffen Beyer)
Subject: Re: vec basics
Message-Id: <6jpdt9$g6f$1@en1.engelschall.com>
[mailed && posted]
Barry Masterson <jbarrm@panix.com> wrote:
> Can anyone here recommend any books, web sites, etc that help
> describe how to understand and use the 'vec' function in perl?
> 'Advanced Perl Programming' (O'Reilly) gives a brief example on
> pages 30-32, but I need more to make use of this function.
If "Advanced Perl Programming" doesn't help you, you will have to experiment,
I'm afraid, in order to find out more.
I suppose you also know "Programming Perl"? (O'Reilly)
> Please advise.
> Thank you.
Are you sure that you want to use "vec"?
There is a module on CPAN offering much more functionality for bit vectors
than "vec", which is also very efficient because its core is written in C.
The name is "Bit::Vector", it's available from
http://www.perl.com/CPAN/modules/by-module/Bit/Bit-Vector-5.3.tar.gz
or
http://www.engelschall.com/u/sb/download/pkg/Bit-Vector-5.3.tar.gz
It is also heavily yet comprehensively documented: 145 kB of documentation.
> Barry Masterson
> jbarrm@panix.com
> --
>>--->--->--->--->--->
> FreeBSD 2.2.6
> <---<---<---<---<---<
Hope this helps!
Yours,
--
Steffen Beyer <sb@engelschall.com>
Free Perl and C Software for Download: www.engelschall.com/u/sb/download/
FreeBSD 2.2.2 (upgrading soon!) :-)
------------------------------
Date: Mon, 18 May 1998 11:09:12 +0200
From: Jean-Louis Leroy <jll@skynet.be>
Subject: Re: while, each & assoc array
Message-Id: <VA.000000be.1e38889c@jll>
In article <6jmqj2$4ih$1@csnews.cs.colorado.edu>, Tom Christiansen wrote:
> Probably what's happening here is that you have CBD (C brain damage).
> This is causes by the fact that an if, while, or for statement
> can take as its target either one single statement, sans braces, or
> or a multiline block enclosed with braces. The perpetual fear, not
> altogether without justification, is that someone might forget the opening
> brace, and end up with [...]
I've always wondered why on Earth braces wouldn't line up, because clearly,
opening and closing braces are on the same 'footing'. This is the first time
I see a reason that makes some sense...
Jean-Louis Leroy
http://ourworld.compuserve.com/homepages/jl_leroy
------------------------------
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 2627
**************************************