[14030] in Perl-Users-Digest
Perl-Users Digest, Issue: 1440 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 19 21:11:22 1999
Date: Fri, 19 Nov 1999 18:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943063813-v9-i1440@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 19 Nov 1999 Volume: 9 Number: 1440
Today's topics:
Re: Serious memory leak in MacPERL? (Tom Sheppard)
Re: signature question (was Re: Help with Stoopid Nutsc <cassell@mail.cor.epa.gov>
Re: Simple help <tomclark@btinternet.com>
Re: Simple help <tomclark@btinternet.com>
Re: Simple help <tomclark@btinternet.com>
Re: Simple help <cassell@mail.cor.epa.gov>
Re: Simple help <tomclark@btinternet.com>
Re: Simple help <lr@hpl.hp.com>
Re: using classes (Kragen Sitaker)
Re: What is a good book on Perl crackbaby1@my-deja.com
Re: What is a good book on Perl <emschwar@rmi.net>
Re: What is a good book on Perl <cassell@mail.cor.epa.gov>
Y2K in perl gqc2017@my-deja.com
Re: Y2K in perl <jeffp@crusoe.net>
Re: Y2K in perl <cassell@mail.cor.epa.gov>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 19 Nov 1999 23:36:57 GMT
From: sheppard@magma.ca (Tom Sheppard)
Subject: Re: Serious memory leak in MacPERL?
Message-Id: <sheppard-1911991837010001@192.168.0.1>
In article <81385q$61r$1@lublin.zrz.tu-berlin.de>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Oh, and of course you can always tie the hash to a disk database, which
> would rid you of all memory woes at the cost of run time. Though I
> must admit that I am not at all certain about the status of the DB*
> modules in MacPerl. One would expect that at least one of them has
> been ported. If you have the choice, I'd recommend DB_File.
I haven't investigated a disk solution ever since I expanded the database
from 1600 movies to 6500 movies. Of course, I'm now at 186,000 movies, so
a disk based solution seems out of the question. It takes a long time now
with a memory based solution running on a G3/400.
As suggested earlier, I tried the approach of preallocating hash buckets
using the technique:
keys %myhash = 500000;
While this seems to help, it's only marginal and does not completely
prevent the memory leak. In my view, when a hash is released via "undef",
then all that memory should be recovered. It isn't. Certainly, when a
script terminates, _all_ memory should be freed. MacPerl doesn't do that
either. I don't know if that's a MacPerl weakness or Perl in general, but
it is disappointing.
Due to the huge size of the Internet Movie Database files I'm using, I
calculate diffs between last week's files and this week's files to
generate a set of delete and add transactions to incrementally update the
FileMaker Pro databases. The files have been written by dumping a hash and
as such appear to be in random order. I'm not crazy about having to sort
50 MB files so that I can use other diff techniques.
------------------------------
Date: Fri, 19 Nov 1999 16:08:08 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: signature question (was Re: Help with Stoopid Nutscrape (Netscape))
Message-Id: <3835E668.7C01D5CD@mail.cor.epa.gov>
Abigail wrote:
>
> John McNamara (jmn.ac.delete@abanet.it) wrote on MMCCLXX September
> MCMXCIII in <URL:news:=vYzOCo=h4C4KzBxKaXHLLf5olLP@4ax.com>:
> ==
> == The regex (and Abagail) are discussed in Chapter 10 of Andrew L.
> == Johnson's Book. In Section 10.6.1 "Prime number regex".
[snip]
> Hmmm, I wonder if they send me a copy of the book then.
> Probably not, times seem to have changed.
Well, I got a free copy. Maybe it's yours. Just try getting
it back.
And I didn't even contribute any code. Except for the snippet
in that exercise titled "Find all the bugs in this horrid bit
of trayfe". :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 19 Nov 1999 23:22:47 -0000
From: "Tom Clark" <tomclark@btinternet.com>
Subject: Re: Simple help
Message-Id: <814m4e$n79$1@neptunium.btinternet.com>
Richard H <rhardicr@mail.ford.com> wrote in message
news:38351470.F70B8CAF@mail.ford.com...
> >
> What you need more expliciity I guess is Larry's code with:
>
> > > > #!/usr/local/bin/perl -w
> > > > use strict;
> > > >
> > > > my %students;
>
> open(DATA, "mydatafile") or die "cant open my file $!";
>
> > > >
> > > > / 99(\d{5}) (.+?) / and $students{$1} = $2 while <DATA>;
> > > >
>
> close DATA;
> open(OUTPUT, ">myoutputfile") or die "cant open output $!";
>
> > > > while (my ($id, $name) = each %students) {
> > > > print "99$id\t$name\n";
>
> change to :
> print OUTPUT "99$id\t$name\n";
>
> > > > }
>
> close OUTPUT;
>
Thanks Richard (and all others!),
Have got Larry's code to work just fine with your additions for the output
file.
If anyone has the time or inclination, could they translate the code below
(which is just the code above but quoted better) into idiot speak so I could
adapt it to perform other operations on the data. I need to extract the
staff that teach particular units (select data from different lines), and
the marks that each student got in each subject i.e. I need to select data
from different lines. As an aside, I need the output to put the data into
SQL insert into commands - presumably I can just edit the print line?
Many thanks,
Tom
#!/usr/local/bin/perl -w
use strict;
my %students;
open(DATA, "Results.txt") or die "cant open my file $!";
/ 99(\d{5}) (.+?) / and $students{$1} = $2 while <DATA>;
close DATA;
open(OUTPUT, ">students.txt") or die "cant open output $!";
while (my ($id, $name) = each %students) {
print OUTPUT "99$id\t$name\n";
}
close OUTPUT;
__END__
A0: Astronomy - Advanced
S6300 Professor Alethia Williams
9901770 Cory Peterson 56
9911224 Frances Fowler 51
9920645 Sarah Watt 59
9921786 Henry Peterson 72
9925656 William Peterson 62
9952429 William Williams 62
------------------------------
Date: Fri, 19 Nov 1999 23:31:07 -0000
From: "Tom Clark" <tomclark@btinternet.com>
Subject: Re: Simple help
Message-Id: <814mk2$p58$1@uranium.btinternet.com>
> As an aside, I need the output to put the data into
> SQL insert into commands - presumably I can just edit the print line?
Managed this one. Looking good!
Still need help with the other stuff though. Its the line:
/ 99(\d{5}) (.+?) / and $students{$1} = $2 while <DATA>;
and:
while (my ($id, $name) = each %students) {
print OUTPUT "99$id\t$name\n";
that I'm struggling with. Especially the first one.
Cheers all,
------------------------------
Date: Fri, 19 Nov 1999 23:43:07 -0000
From: "Tom Clark" <tomclark@btinternet.com>
Subject: Re: Simple help
Message-Id: <814nai$pdm$1@uranium.btinternet.com>
Yet another one...hope no one minds.
How would I adapt the following to extract the id numbers and names of
staff...?
use strict;
my %students;
open(DATA, "Results.txt") or die "cant open my file $!";
/ 99(\d{5}) (.+?) / and $students{$1} = $2 while <DATA>; ####I assume
this is the line that needs edited.
close DATA;
open(OUTPUT, ">students.sql") or die "cant open output $!";
while (my ($id, $name) = each %students) {
print OUTPUT "INSERT INTO Students VALUES ('99$id','$name') ;\n" ;
}
close OUTPUT;
I promise I won't post again until this one has been answered.... ;)
Best regards,
------------------------------
Date: Fri, 19 Nov 1999 16:06:26 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Simple help
Message-Id: <3835E602.980411F1@mail.cor.epa.gov>
Tom Clark wrote:
>
> Guys,
and Dolls...
> Even with your help, I'm foundering in my own ineptitude. I've tried
> cutting and pasting all the code that has been posted and have got nowhere.
> :((
Tom, it may be time to learn some Perl in a more organized
fashion. That may help you a lot. You can start with this
web tutorial:
http://www.netcat.co.uk/rob/perl/win32perltut.html
and you may also want to get Andrew Johnson's book
"Elements of Programming with Perl" from Manning.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sat, 20 Nov 1999 00:33:50 -0000
From: "Tom Clark" <tomclark@btinternet.com>
Subject: Re: Simple help
Message-Id: <814qae$qm4$1@neptunium.btinternet.com>
David Cassell <cassell@mail.cor.epa.gov> wrote in message
news:3835E602.980411F1@mail.cor.epa.gov...
> Tom Clark wrote:
> >
> > Guys,
>
> and Dolls...
>
Of course. ;)
> Tom, it may be time to learn some Perl in a more organized
> fashion. That may help you a lot. You can start with this
> web tutorial:
> http://www.netcat.co.uk/rob/perl/win32perltut.html
> and you may also want to get Andrew Johnson's book
> "Elements of Programming with Perl" from Manning.
Thanks David,
I had looked around a bit on the web but hadn't come across anything that
seemed particularly accessible. I'm doing a databases course at University
that requires me to extract data from the file and perform operations on it
to put it into a database. I expect that I might (just!) be able to manage
this problem with Java, but thought that Perl was more appropriate.
Thanks for the reccomendation,
I'll get on it to see what I can manage....
Best regards,
Tom
------------------------------
Date: Fri, 19 Nov 1999 17:42:54 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Simple help
Message-Id: <MPG.129f9c7ebfdcfe3d98a242@nntp.hpl.hp.com>
In article <814nai$pdm$1@uranium.btinternet.com> on Fri, 19 Nov 1999
23:43:07 -0000, Tom Clark <tomclark@btinternet.com> says...
> Yet another one...hope no one minds.
Well, people are telling you to learn more of the basics.
> How would I adapt the following to extract the id numbers and names of
> staff...?
>
> use strict;
>
> my %students;
>
> open(DATA, "Results.txt") or die "cant open my file $!";
Small matter of policy: Use the filehandle DATA only for the stuff
being read in after the __END__ or __DATA__ division. For ordinary
filehandles, use IN or FILE or whatever seems best, not DATA.
> / 99(\d{5}) (.+?) / and $students{$1} = $2 while <DATA>; ####I assume
> this is the line that needs edited.
Right. And you'll have to figure out enough about regexes to work out
how to distinguish the particular lines you are looking for, and to
extract the fields you want.
You should do all this on one pass, in which case you would need two
hashes, and the program would be better structured thus:
while (<IN>) {
# Find students and write to their hash.
# Find staff and write to their hash.
}
> close DATA;
> open(OUTPUT, ">students.sql") or die "cant open output $!";
>
> while (my ($id, $name) = each %students) {
> print OUTPUT "INSERT INTO Students VALUES ('99$id','$name') ;\n" ;
> }
A word of warning on that SQL: A student named O'Brian will wreak havoc
with your program. To fix that, you'll have to double each single
quote, so a name like "O'Brian" becomes "O''Brian". That can be done
with a regex and a substitution. How to is left as an exercise for the
student (you).
> close OUTPUT;
>
> I promise I won't post again until this one has been answered.... ;)
Oh, no! Not more...
> Best regards,
And to you. GO (California Golden) BEARS! Beat Satanfurd!!!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 19 Nov 1999 23:06:10 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: using classes
Message-Id: <CJkZ3.29002$YI2.1350006@typ11.nn.bcandid.com>
In article <UZiZ3.28720$YI2.1332870@typ11.nn.bcandid.com>,
Kragen Sitaker <kragen@dnaco.net> wrote:
>In article <813veg$tmc$1@nnrp1.deja.com>, sp00fD <sp00fD@yahoo.com> wrote:
>>I'm somewhat familiar with Python and have used it on a couple of
>>occassions. I'm curious, is there a way to directly use a class/module
>>as in python?
>
>Ask in comp.lang.python.
Oops! I missed that little "as". Sorry.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 19 Nov 1999 23:49:43 GMT
From: crackbaby1@my-deja.com
Subject: Re: What is a good book on Perl
Message-Id: <814nmm$g5v$1@nnrp1.deja.com>
Two books you must have...
Programming Perl (Oreilly)
MySQL & msql (Oreilly)
In article <814gi7$ptv$1@nntp2.atl.mindspring.net>,
"Trulits" <trulits@hotmail.com> wrote:
> I am interested in learning Perl.
>
> Is that what most cgi is written in these days?
> I need to learn how to process forms
> create and maintain databases
> perhaps create, shopping carts, mailing lists apps, and guest book
apps.
>
> What is a good book to learn?
>
> Thanks
>
> Tru
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 19 Nov 1999 17:09:50 -0700
From: Eric The Read <emschwar@rmi.net>
Subject: Re: What is a good book on Perl
Message-Id: <xkfwvrexbu9.fsf@valdemar.col.hp.com>
"Trulits" <trulits@hotmail.com> writes:
> What is a good book to learn?
You can get a list of critiques by TomC at <URL:http://www.perl.com/
pub/language/critiques/index.html>.
-=Eric
--
"Cutting the space budget really restores my faith in humanity. It
eliminates dreams, goals, and ideals and lets us get straight to the
business of hate, debauchery, and self-annihilation."
-- Johnny Hart
------------------------------
Date: Fri, 19 Nov 1999 16:13:42 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: What is a good book on Perl
Message-Id: <3835E7B6.FC213A62@mail.cor.epa.gov>
Trulits wrote:
>
> I am interested in learning Perl.
Good.
> Is that what most cgi is written in these days?
A lot of CGI scripts are written using the Perl programming
language. But as you know, Perl is not CGI.
> I need to learn how to process forms
> create and maintain databases
> perhaps create, shopping carts, mailing lists apps, and guest book apps.
Some of those are perhaps larger tasks than you want to start
off tackling. Others are simple enough once you learn about
Perl and its modules.
> What is a good book to learn?
I recommend you start with "Elements of Programming with Perl"
by Andrew Johnson. It won't teach you how to write a shopping
cart program. But it will teach you about Perl, and about
learning to program.
After that, you can move to some of the CGI books, and to some
of the CGI programs available on the web. But you will then
be able to see what is bad code, and how to repair it.
Good luck,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 19 Nov 1999 23:20:52 GMT
From: gqc2017@my-deja.com
Subject: Y2K in perl
Message-Id: <814m0h$f0n$1@nnrp1.deja.com>
Hi, I am using localtime() in perl to get the current year. Now what
can I do to make my code Y2K compliant?
Thank you!!!!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 19 Nov 1999 18:59:04 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Y2K in perl
Message-Id: <Pine.GSO.4.10.9911191858460.26722-100000@crusoe.crusoe.net>
[posted & mailed]
> Hi, I am using localtime() in perl to get the current year. Now what
> can I do to make my code Y2K compliant?
Read its docs!
--
MIDN 4/C PINYAN, USNR, NROTCURPI http://www.pobox.com/~japhy/
jeff pinyan: japhy@pobox.com perl stuff: japhy+perl@pobox.com
"The Art of Perl" http://www.pobox.com/~japhy/book/
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
------------------------------
Date: Fri, 19 Nov 1999 16:41:03 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Y2K in perl
Message-Id: <3835EE1F.DD3909CD@mail.cor.epa.gov>
gqc2017@my-deja.com wrote:
>
> Hi, I am using localtime() in perl to get the current year. Now what
> can I do to make my code Y2K compliant?
You'll have to read the documentation. Use the perldoc program
to help you. localtime() is already Y2K-compliant, but that
won't be clear for another month and a half. You see,
localtime() doesn't return the year. It returns an offset from
the correct year. Just like it returns an offset from the
correct month.
So. What *does* your code look like right now? If in any part
of your date-handling you are gluing a '19' to the front of the
year, you're going to be embarrassed on Jan first.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V9 Issue 1440
**************************************