[11340] in Perl-Users-Digest
Perl-Users Digest, Issue: 4940 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 19 13:07:28 1999
Date: Fri, 19 Feb 99 10:00:28 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 19 Feb 1999 Volume: 8 Number: 4940
Today's topics:
${%x}{"a"} = "b"; # Why does this work !!!! <tony.edwardson@usa.net>
Re: ${%x}{"a"} = "b"; # Why does this work !!!! <smiles@wfubmc.edu>
Re: ${%x}{"a"} = "b"; # Why does this work !!!! (M.J.T. Guy)
Re: Anybody get .pl scripts to run on Win32 Perl and Ap <joec@impacttech.com>
Calendar Script <bmb@ginger.libs.uga.edu>
Error Inserting into Access mark.haley@trw.com
Re: FAQ 5.16: How can I reliably rename a file? <jdf@pobox.com>
FAQ 8.14: How do I modify the shadow password file on a <perlfaq-suggestions@perl.com>
FAQ 8.17: How can I measure time under a second? <perlfaq-suggestions@perl.com>
FAQ 8.18: How can I do an atexit() or setjmp()/longjmp( <perlfaq-suggestions@perl.com>
FAQ 8.19: Why doesn't my sockets program work under Sys <perlfaq-suggestions@perl.com>
Re: File Locking Question <undefined@null.com>
Re: Help with a simple problem <aqumsieh@matrox.com>
Re: Help, needed to create a 3 tier hash/array structur <jglascoe@giss.nasa.gov>
Re: Help, needed to create a 3 tier hash/array structur droby@copyright.com
Re: How do you: extract data from Netware NDS <jdubois@keane.com>
MKDIR colin.taylor@ec.gc.ca
Re: MKDIR <dominik.furger@bluewin.ch>
Re: perl compiled code cacheing <jdf@pobox.com>
Re: perl compiled code cacheing (Sam Curren)
Re: Perl evangelism (Randal L. Schwartz)
Re: Perl evangelism (Sam Curren)
Printing all environment variables (Christian M. Aranda)
Re: Printing all environment variables (Christian M. Aranda)
Re: Printing all environment variables <jglascoe@giss.nasa.gov>
Process uses too much memory. m_i_c_h_a_e_l@my-dejanews.com
removing HTML tags froma file (Cybernetic Bear)
Re: returnvalue from system() <tbriles@austin.ibm.com>
Re: returnvalue from system() <dboorstein@ixl.com>
SRC: fwdport -- act as proxy forwarder for dedicated se <tchrist@mox.perl.com>
tie complex data in DBM files <smiles@wfubmc.edu>
Re: tie complex data in DBM files (Sam Curren)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 19 Feb 1999 15:34:59 +0000
From: Tony Edwardson <tony.edwardson@usa.net>
Subject: ${%x}{"a"} = "b"; # Why does this work !!!!
Message-Id: <36CD84A3.3AB2726@usa.net>
Can anyone explain why the following snippet works
#!/apps/exe/perl5.004.04 -w
my %x;
${%x}{"a"} = "b"; # Why does this work !!!!
foreach $key (keys %x) {
print "$key=$x{$key}\n";
}
The output is
a=b
What is happening in the ${%x}{"a"} construct ?
Any ideas anyone ?
Tony
-----------------------
Tony Edwardson
Merrill Lynch Europe PLC
0171-906 7587
edwarton@ml.com
or
tony.edwardson@usa.net
------------------------------
Date: Thu, 18 Feb 1999 11:52:14 -0500
From: Steve Miles <smiles@wfubmc.edu>
Subject: Re: ${%x}{"a"} = "b"; # Why does this work !!!!
Message-Id: <36CC453E.DAFCEB76@wfubmc.edu>
${%x}{"a"} = "b";
is the same thing as saying:
%x = ( a => b); #normal hash structure
or $x{"a"} = "b"; would be the same thing.
$x{"a"} means key "a" in the hash "x", and of course, it equals "b".
Steve
==================================
Steve Miles (smiles@wfubmc.edu)
http://www.groundbreak.com
Wake Forest University School of Medicine
5019 Hanes, Medical Center Blvd.
Winston-Salem, NC 27157
Phone: 336.716.0454 FAX: 336.716.7200
==================================
Tony Edwardson wrote:
> Can anyone explain why the following snippet works
> #!/apps/exe/perl5.004.04 -w
>
> my %x;
>
> ${%x}{"a"} = "b"; # Why does this work !!!!
>
> foreach $key (keys %x) {
> print "$key=$x{$key}\n";
> }
>
> The output is
> a=b
>
> What is happening in the ${%x}{"a"} construct ?
>
> Any ideas anyone ?
>
> Tony
> -----------------------
> Tony Edwardson
> Merrill Lynch Europe PLC
> 0171-906 7587
> edwarton@ml.com
> or
> tony.edwardson@usa.net
------------------------------
Date: 19 Feb 1999 17:51:02 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: ${%x}{"a"} = "b"; # Why does this work !!!!
Message-Id: <7ak8a6$eoc$1@pegasus.csx.cam.ac.uk>
Tony Edwardson <tony.edwardson@usa.net> wrote:
>my %x;
>
>${%x}{"a"} = "b"; # Why does this work !!!!
This is an undocumented (mis)feature. Wherever you can write a
hash reference, you can instead write a hash, and Perl supplies an
implied \ . Similarly for array references and arrays. So for
example you can write
@a->[0]
and it means the same as
$a[0] .
There was some discussion of this on p5p. IIRC the consensus was that
this was a mistake and oughtn't to have been put in; OTOH there was
reluctance to remove it for compatibility reasons.
Mike Guy
------------------------------
Date: Fri, 19 Feb 1999 10:08:44 -0600
From: "Joseph Henry Chambers" <joec@impacttech.com>
Subject: Re: Anybody get .pl scripts to run on Win32 Perl and Apache 1.3.3. &#$%*Damn MS Windoze file associations.
Message-Id: <7ak2be$6f4$1@fir.prod.itd.earthlink.net>
Allan M. Due wrote in message <7ahjti$j8h$1@camel0.mindspring.com>...
>...
>:This is not currently true.
>:
>:I installed apache and with its default settings was running cgi-scripts
>:with perl inside of 45 minutes (that included the Perl and the Apache
>:downloads and installations. I did not have to do any apache
associations.
>:My Windows NT associations sufficed for the Perl side.
>:
>
>
>1.3.3? Really? You didn't have to modify the .conf files? Fascinating,
>that is going to make my life easier.
>
>AmD
>
The only changes I made to .conf were the following
Added /images/ alias to be more compatible with some existing scripts.
Added /cgi-bin/<filename>.pl to file load, because I didn't want to type in
the url every time.
I see a version of 1.3, so I am not sure about 1.3.3. But my experience is
that getting the system up is easy. Making significant modifications, like
you would see on a Linux box may be more difficult, but I haven't seen
significant complexity yet.
Joe
------------------------------
Date: Fri, 19 Feb 1999 11:52:37 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Calendar Script
Message-Id: <Pine.A41.4.02.9902191118560.61586-100000@ginger.libs.uga.edu>
About a year and a half ago, I wrote a calendar script that I named,
mycal. I wanted a combination of `cal` and `calendar` that would read my
email and provide me with a nicely formatted plain text calendar. I
decided that since reading email is the one thing I'm *sure* to
do every day, if my calendar maintenance were tied in with my email, I'd
be more likely to use it. I've been very happy with it, and I thought I'd
share it with others who might benefit:
http://www.diddlysquat.com/brad/perl/mycal
(If you're wondering about that domain name, don't worry--it doesn't mean
a thing. :-)
Mycal is not a CGI script, though it is able to create a calendar in HTML.
It can be run from the command line, but most often I run it as a cron
process. Following are some of the ways I have found it useful:
1. Every hour it updates an html page containing a calendar for our work
group. We maintain multiple files of calendar entries that include
call schedules, regular meetings, academic calendar items, and the
usual holidays.
2. Also every hour it updates my personal html calendar page that includes
some of the information from the work group calendar as well as
personal appointments and reminders.
3. At 8am every day, the work group calendar is emailed to the work group
email list, and my personal calendar is emailed to me.
4. At 6am every day, all of my appointments for the day are emailed to my
regular email address, as well as to an email address that makes its
way to my alphanumeric pager. This way, I can remember to wear a coat
and tie if I have a "suit" sort of meeting planned.
5. Every hour from 7am to 11pm, mycal pages and emails reminders of any
appointments coming up in the next couple of hours.
6. Adding calendar entries is as simple as editing one or more of the
input files, or simply emailing a reminder to myself. Mycal reads the
Subject lines of my email and adds things to my calendar even before
I've read the message.
This script is far from perfect, but we have been using it daily for about
15 months. I'd be thrilled to know that others find it useful. I'll
be glad to help out with corrections or tips, and would welcome any code
improvements.
Regards,
Brad Baxter
bmb@mail.libs.uga.edu
------------------------------
Date: Fri, 19 Feb 1999 16:55:14 GMT
From: mark.haley@trw.com
Subject: Error Inserting into Access
Message-Id: <7ak51c$sqp$1@nnrp1.dejanews.com>
I have an INSERT query that I try to run in a Perl script (Perl 5.07, using
WIN32::ODBC). I get the following error message:
Error: [-3035] [1] [0] "[Microsoft][ODBC Microsoft Access 97 Driver] Operation
must use an updatable query."
The query is as follows:
$sql = ("INSERT INTO HitCounter (User) VALUES ('$user')");
$user is a parameter passed to the sub (and does come through with the
correct value), HitCounter is a table in the database, and User is a field in
the table. I have a user log in (verifies username and password), which works
fine. I want to log the user name, time of access(this field is set to
default to Now() in the table definition), and total number of accesses
(autonumber field in the table).
Where have I screwed up, how do I fix it, and what's your best stock tip?
Thanks for any help!
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 19 Feb 1999 12:08:19 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: FAQ 5.16: How can I reliably rename a file?
Message-Id: <m3aeyab9to.fsf@joshua.panix.com>
Tom Christiansen <tchrist@mox.perl.com> writes:
> In comp.lang.perl.misc,
> ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> :This description is has serious flaws, since it does not explain the
> :difference of rename()ing on POSIX and DOSISH systems.
>
> No sir, it's your embarrassingly miserable excuse for a disk loader
> that has serious flaws.
[etc.]
Listening to these guys going at it is like being one of the troopers
when they opened the Ark in "Raiders of the Lost Ark".
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 19 Feb 1999 07:53:05 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 8.14: How do I modify the shadow password file on a Unix system?
Message-Id: <36cd7ad1@csnews>
(This excerpt from perlfaq8 - System Interaction
($Revision: 1.36 $, $Date: 1999/01/08 05:36:34 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq8.html
if your negligent system adminstrator has been remiss in his duties.)
How do I modify the shadow password file on a Unix system?
If perl was installed correctly, and your shadow library was written
properly, the getpw*() functions described in the perlfunc manpage
should in theory provide (read-only) access to entries in the shadow
password file. To change the file, make a new shadow password file (the
format varies from system to system - see the passwd(5) manpage for
specifics) and use pwd_mkdb(8) to install it (see the pwd_mkdb(5)
manpage for more details).
--
I know it's weird, but it does make it easier to write poetry in perl. :-)
--Larry Wall in <7865@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 19 Feb 1999 09:03:48 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 8.17: How can I measure time under a second?
Message-Id: <36cd8b64@csnews>
(This excerpt from perlfaq8 - System Interaction
($Revision: 1.36 $, $Date: 1999/01/08 05:36:34 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq8.html
if your negligent system adminstrator has been remiss in his duties.)
How can I measure time under a second?
In general, you may not be able to. The Time::HiRes module (available
from CPAN) provides this functionality for some systems.
If your system supports both the syscall() function in Perl as well as a
system call like gettimeofday(2), then you may be able to do something
like this:
require 'sys/syscall.ph';
$TIMEVAL_T = "LL";
$done = $start = pack($TIMEVAL_T, ());
syscall( &SYS_gettimeofday, $start, 0) != -1
or die "gettimeofday: $!";
##########################
# DO YOUR OPERATION HERE #
##########################
syscall( &SYS_gettimeofday, $done, 0) != -1
or die "gettimeofday: $!";
@start = unpack($TIMEVAL_T, $start);
@done = unpack($TIMEVAL_T, $done);
# fix microseconds
for ($done[1], $start[1]) { $_ /= 1_000_000 }
$delta_time = sprintf "%.4f", ($done[0] + $done[1] )
-
($start[0] + $start[1] );
--
#define SVs_RMG 0x00008000 /* has random magical methods */
--Larry Wall, from sv.h in the v5.0 perl distribution
------------------------------
Date: 19 Feb 1999 09:43:40 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <36cd94bc@csnews>
(This excerpt from perlfaq8 - System Interaction
($Revision: 1.36 $, $Date: 1999/01/08 05:36:34 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq8.html
if your negligent system adminstrator has been remiss in his duties.)
How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Release 5 of Perl added the END block, which can be used to simulate
atexit(). Each package's END block is called when the program or thread
ends (see the perlmod manpage manpage for more details).
For example, you can use this to make sure your filter program managed
to finish its output without filling up the disk:
END {
close(STDOUT) || die "stdout close failed: $!";
}
The END block isn't called when untrapped signals kill the program,
though, so if you use END blocks you should also use
use sigtrap qw(die normal-signals);
Perl's exception-handling mechanism is its eval() operator. You can use
eval() as setjmp and die() as longjmp. For details of this, see the
section on signals, especially the time-out handler for a blocking
flock() in the section on "Signals" in the perlipc manpage and chapter 6
of the Camel.
If exception handling is all you're interested in, try the exceptions.pl
library (part of the standard perl distribution).
If you want the atexit() syntax (and an rmexit() as well), try the
AtExit module available from CPAN.
--
I'm sure that that could be indented more readably, but I'm scared of
the awk parser. --Larry Wall in <6849@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 19 Feb 1999 10:43:42 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 8.19: Why doesn't my sockets program work under System V (Solaris)? What does the error message "Protocol not supported" mean?
Message-Id: <36cda2ce@csnews>
(This excerpt from perlfaq8 - System Interaction
($Revision: 1.36 $, $Date: 1999/01/08 05:36:34 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq8.html
if your negligent system adminstrator has been remiss in his duties.)
Why doesn't my sockets program work under System V (Solaris)? What does the error message "Protocol not supported" mean?
Some Sys-V based systems, notably Solaris 2.X, redefined some of the
standard socket constants. Since these were constant across all
architectures, they were often hardwired into perl code. The proper way
to deal with this is to "use Socket" to get the correct values.
Note that even though SunOS and Solaris are binary compatible, these
values are different. Go figure.
--
"The purpose of most computer languages is to lengthen your resume by
a word and a comma." --Larry Wall
------------------------------
Date: Fri, 19 Feb 1999 11:34:53 -0500
From: "Bill Sanders" <undefined@null.com>
Subject: Re: File Locking Question
Message-Id: <7ak3rs$qsb@news1.snet.net>
The posts you mention were not found by my newsreader, but a search on
Dejanews turned them up.
Thank you for the point in the right direction. Your sarcasm was also mildly
amusing.
>:open (COUNT, ">$count_file") || die "Unable to open $count_file: $!\n";
>:flock(COUNT, 2);
>
>Gee, that's clever -- shutting the barn door once the horses have
>escaped.
------------------------------
Date: Fri, 19 Feb 1999 11:35:49 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Help with a simple problem
Message-Id: <x3yww1el5az.fsf@tigre.matrox.com>
Ophir Marko <ophir@saifun.com> writes:
> # /local/perl/bin/perl -w
Your shebang is all messed up. What you have is just a comment.
> $file = <ARGV>;
> open(MYFILE, ">$file");
Here you open() $file for writing (creating it if it didn't exist, and
deleting its contents if it did exist). You don't test to see whether
your open() succeeded or not.
> split;
This splits $_ on whitespace. What are the contents of $_ ?? It also
does an implicit assignment to @_ .. which is deprecated.
> @lines = @_;
>
> # And this is were I'm stuck. Like I said,
> # It has to search for a word in a line(MOS)
> # and then transfer the line with the word to
> # a new file and copy the file to /home/ophir/backup/
What happened when you ran your code? I got at least 3 warnings and an
error.
You need major help my friend. Get yourself a copy of the Llama book
(Learning Perl, by R. Schwartz and T. Christiansen, published by
O'Reilly) and read it from cover to cover.
Ala
------------------------------
Date: Fri, 19 Feb 1999 11:30:48 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: lee.gammell@ctaylor.co.uk
Subject: Re: Help, needed to create a 3 tier hash/array structure
Message-Id: <36CD91B8.E31DADDD@giss.nasa.gov>
[courtesy copy of post sent to cited author]
hi Lee,
lee.gammell@ctaylor.co.uk wrote:
>
> $VOL{"v1"} = 100;
> $VOL{"v1"}{"p1"} = 100;
no, the value of $VOL{"v1"} cannot be both 100 and a hash
reference at once. You're trying to do:
%VOL = ("v1" => 100, "v1" => {"p1" => 100});
> $VOL{"v1"}{"p1"}{"s1"} = 25;
%VOL = ("v1" => 100, "v1" => {"p1" => 100, "p1" => {"s1" => 25}});
again, is $VOL{"v1"}{"p1"} a hash reference or an integer?
> Any hints would be appreciated by a perl novice,
$VOL{"v1"}{"int"} = 100;
$VOL{"v1"}{"hash"}{"p1"}{"int"} = 25;
$VOL{"v1"}{"hash"}{"p1"}{"hash"}{"s1"} = 25;
Jay Glascoe
--
http://www.giss.nasa.gov/cgi-bin/csci/change.pl
------------------------------
Date: Fri, 19 Feb 1999 17:08:48 GMT
From: droby@copyright.com
Subject: Re: Help, needed to create a 3 tier hash/array structure
Message-Id: <7ak5qn$tft$1@nnrp1.dejanews.com>
In article <7ajrp8$jpb$1@nnrp1.dejanews.com>,
lee.gammell@ctaylor.co.uk wrote:
> I would like to create a 3 tier structure using
>
> volumes
> have 1 or more plexes
> have 1 or more subdisks
>
> for each volume,plex and subdisk I need to store its size
>
> #! /usr/bin/perl
>
#!/usr/bin/perl -w
use strict "refs";
> # try to create a 3 tier structure ...
> #
> # create a sample entry for volume v1
> #
> $VOL{"v1"} = 100;
> $VOL{"v1"}{"p1"} = 100;
You just created a hash named %100. strict "refs" would have caught this.
> $VOL{"v1"}{"p1"}{"s1"} = 25;
> $VOL{"v1"}{"p1"}{"s2"} = 25;
> $VOL{"v1"}{"p1"}{"s3"} = 25;
> $VOL{"v1"}{"p1"}{"s4"} = 25;
> $VOL{"v1"}{"p2"} = 100;
> $VOL{"v1"}{"p2"}{"s1"} = 25;
> $VOL{"v1"}{"p2"}{"s2"} = 25;
> $VOL{"v1"}{"p2"}{"s3"} = 25;
> $VOL{"v1"}{"p2"}{"s4"} = 25;
>
Using test data with more variety might have given you some hints too. You've
put many things into your accidental %100 variable. ;-)
>
> Any hints would be appreciated by a perl novice,
>
The basic lesson is that you can't use the same variable as both a numeric or
string scalar and as a hashref.
You need to introduce further structure, either by making 'SIZE' a hash key
and distinguishing it in you traversal logic, or by adding a list structure
to have each layer of your heirarchy hold a scalar size and a hashref as two
entries in a list.
Consult perlref and perllol for lots of help on this stuff. Also perltoot
might lead you to an object view on this sort of structure.
And always use strict, at least for references. It prevents alot of
headaches.
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 18 Feb 1999 13:34:57 -0500
From: Joseph DuBois <jdubois@keane.com>
Subject: Re: How do you: extract data from Netware NDS
Message-Id: <36CC5D51.17AA68E1@keane.com>
Take a look at Net-LDAPapi off of CPAN. At one time we did get it
running, for queries. We then switched over to Netscape directory
server, so we switched the code. But is was working...
jgrain wrote:
> Does anyone have example scripts to extract data from Netware 4.11 NDS
> using data posted in a HTML form?
>
> I know this is possible the setup I am running is a Netware 4.11 server
> running Netscapes Fastrack Webserver. A little research has shown that I
> just need to be able to make calls, via server side scripting
> to Netware's NDS api. I have so far found no documentation that shows
> specific examples using any
> server side scripting
--
-------------------------------------------------------
Joseph DuBois /Int(er|ra)net Grunt/
mailto:jdubois@keane.com (Work) http://www.keane.com/
------------------------------
Date: Fri, 19 Feb 1999 15:57:58 GMT
From: colin.taylor@ec.gc.ca
Subject: MKDIR
Message-Id: <7ak1m0$pgt$1@nnrp1.dejanews.com>
I am very new to Perl and am trying to create a new directory with a mkdir
command but it doesn't work. I get a message saying I am missing a parameter.
The code I type is
mkdir 'c:\dummy'
I know I am missing the mode parameter, but cannot figure out what I should
put in for a new directory I want to add files to with my Perl program.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 19 Feb 1999 17:47:04 +0100
From: Dominik Furger <dominik.furger@bluewin.ch>
Subject: Re: MKDIR
Message-Id: <36CD9587.4E456C2@bluewin.ch>
Things like this should do what you need:
$TMPDATA="$DATADIR/tmp";
mkdir ("${TMPDATA}",0755) ;
colin.taylor@ec.gc.ca wrote:
> I am very new to Perl and am trying to create a new directory with a mkdir
> command but it doesn't work. I get a message saying I am missing a parameter.
> The code I type is
>
> mkdir 'c:\dummy'
>
> I know I am missing the mode parameter, but cannot figure out what I should
> put in for a new directory I want to add files to with my Perl program.
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 19 Feb 1999 11:59:56 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: samc@empirewest.com (Sam Curren)
Subject: Re: perl compiled code cacheing
Message-Id: <m3d836ba7n.fsf@joshua.panix.com>
samc@empirewest.com (Sam Curren) writes:
> It seems to me that if the perl engine would cache compiled code
> between runs, then a script would run faster, eliminating the need
> to recompile each run.
Just to be clear about this, the script would not "run faster", but
merely begin running sooner.
The thing is that so many scripts have run times on the order of
seconds, tens of seconds, and hundreds of seconds that savings on the
order of tenths of a second are not worth the engineering involved.
When I'm processing a 1.5 gig web log file, for example, I'm not so
concerned about compile-time.
In an application where tenths of seconds are crucial, you might
consider using C or C++.
> I understand about mod_perl, but it seems as though it's a solution
> that avoids the problem.
In what way does it "avoid the problem"? It seems to do exactly what
you want.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Fri, 19 Feb 1999 09:52:39 -0800
From: samc@empirewest.com (Sam Curren)
Subject: Re: perl compiled code cacheing
Message-Id: <MPG.113744bea91bbd3f9896e1@news.sonic.net>
In article <m3d836ba7n.fsf@joshua.panix.com>, jdf@pobox.com says...
> samc@empirewest.com (Sam Curren) writes:
>
> > It seems to me that if the perl engine would cache compiled code
> > between runs, then a script would run faster, eliminating the need
> > to recompile each run.
>
> Just to be clear about this, the script would not "run faster", but
> merely begin running sooner.
Thanks. That's what I meant, but that was a perfect clarification.
> The thing is that so many scripts have run times on the order of
> seconds, tens of seconds, and hundreds of seconds that savings on the
> order of tenths of a second are not worth the engineering involved.
> When I'm processing a 1.5 gig web log file, for example, I'm not so
> concerned about compile-time.
If you save on tenth of a second on a script that is run 5,000 times in a
day, you would save 8 minutes and 20 seconds of processor time. That
might not be useful for scripts that take 5 minutes to run, but many
scripts, particularly those that deal with websites (CGI programs, etc.)
would save some time. Not much, I admit, but isn't efficency the idea?
>
> In an application where tenths of seconds are crucial, you might
> consider using C or C++.
I could use another method entirely, and another OS. But I'd rather
improve the one I like to use.
> > I understand about mod_perl, but it seems as though it's a solution
> > that avoids the problem.
>
> In what way does it "avoid the problem"? It seems to do exactly what
> you want.
No. To my [possibly incorrect] understanding, you have to make a
modification to the web server. While that may be easy for some, I
usually run my scripts on servers that I have no controll over. It seems
that a simple fix to an upcomming perl release would improve things, even
if only a little, for situations like this, where I have no controll.
Second, mod_perl requires [I think] the server to hold the script in
memory. This only compiles the script once, but it also consumes some
resources. This 'avoids the problem' by cacheing the compiled code in
temporary memory, consuming resources. If it were stored in a temporary
file on the server, then that compile time could be eliminated (or at
least greatly reduced) without the overhead.
I'm not trying to replace mod_perl. I'm looking for a different
optomization method that can benefit more scripts with less trouble.
-Sam
------------------------------
Date: 19 Feb 1999 08:12:48 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl evangelism
Message-Id: <m1emnm4bjz.fsf@halfdome.holdit.com>
>>>>> "VicodinES" == VicodinES /CB /TNN <jsteinberger@usweb.com> writes:
VicodinES> Just thought I'd point out that Ask Jeeves is now
VicodinES> http://www.ask.com - they got that cool new domain name. I
VicodinES> think the old url will still work for some time, but the
VicodinES> new one's a keeper plus it's less typing and more
VicodinES> memorable.
And don't ask me how I know this, but the entire Ask Jeeves database
is built in to www.altavista.com, providing a uniform interface to
both smart answers and index answers. (And Altavista runs it on
dozens of distributed machines, not the few that the www.ask.com
runs.)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Fri, 19 Feb 1999 09:55:31 -0800
From: samc@empirewest.com (Sam Curren)
Subject: Re: Perl evangelism
Message-Id: <MPG.1137456c173309ca9896e2@news.sonic.net>
Looking for less typing? try www.aj.com for www.askjeeves.com or
www.ask.com (although I agree with ask.com's coolness).
Altavista fan? www.av.com resolves to www.altavista.com
As for altavista containing the database, I would imagine that they would
simply query askjeeves databases in the background, not replicate the
database.
my $0.02
-Sam
In article <m1emnm4bjz.fsf@halfdome.holdit.com>, merlyn@stonehenge.com
says...
> >>>>> "VicodinES" == VicodinES /CB /TNN <jsteinberger@usweb.com> writes:
>
> VicodinES> Just thought I'd point out that Ask Jeeves is now
> VicodinES> http://www.ask.com - they got that cool new domain name. I
> VicodinES> think the old url will still work for some time, but the
> VicodinES> new one's a keeper plus it's less typing and more
> VicodinES> memorable.
>
> And don't ask me how I know this, but the entire Ask Jeeves database
> is built in to www.altavista.com, providing a uniform interface to
> both smart answers and index answers. (And Altavista runs it on
> dozens of distributed machines, not the few that the www.ask.com
> runs.)
>
>
------------------------------
Date: Fri, 19 Feb 1999 16:27:55 GMT
From: christian.arandaNOSPAM@NOSPAMiiginc.com (Christian M. Aranda)
Subject: Printing all environment variables
Message-Id: <36cd8eef.2054873@news.bbn.com>
I have a script which is being called by an application. When the
application calls said script, it doesn't work. When I run the script
on the command line through the debugger, it works fine.
My theory:
The environment variables which are set when I log in are different
from the variables set when the application logs in, thus causing the
script not to work.
Now, I know that I can print %ENV and get all the environment
variables. But because it's a hash, it won't print very legibly. Is
there any good way to print them all so I can compare them?
TIA -
------------------------------
Date: Fri, 19 Feb 1999 17:25:26 GMT
From: christian.arandaNOSPAM@NOSPAMiiginc.com (Christian M. Aranda)
Subject: Re: Printing all environment variables
Message-Id: <36ce9d37.5710531@news.bbn.com>
On Fri, 19 Feb 1999 12:01:50 -0500, Jay Glascoe
<jglascoe@giss.nasa.gov> wrote:
>
>my @env_keys = keys %ENV;
>@env_keys = sort { $a cmp $b } @env_keys;
>for my $key (@env_keys)
>{
> my $val = $ENV{$key};
> print "$key\t$val\n"
>}
>
>hth, hope it's helpful.
>
Very much so. Thanks for the help!
> Jay Glascoe
>--
>http://www.giss.nasa.gov/cgi-bin/csci/change.pl
------------------------------
Date: Fri, 19 Feb 1999 12:01:50 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: "Christian M. Aranda" <christian.arandaNOSPAM@NOSPAMiiginc.com>
Subject: Re: Printing all environment variables
Message-Id: <36CD98FE.3CE3C41B@giss.nasa.gov>
[courtesy copy of post sent to cited author]
hi Christian,
"Christian M. Aranda" wrote:
>
> Now, I know that I can print %ENV and get all the environment
> variables. But because it's a hash, it won't print very legibly. Is
> there any good way to print them all so I can compare them?
my @env_keys = keys %ENV;
@env_keys = sort { $a cmp $b } @env_keys;
for my $key (@env_keys)
{
my $val = $ENV{$key};
print "$key\t$val\n"
}
>
> TIA -
hth, hope it's helpful.
Jay Glascoe
--
http://www.giss.nasa.gov/cgi-bin/csci/change.pl
------------------------------
Date: Fri, 19 Feb 1999 17:00:30 GMT
From: m_i_c_h_a_e_l@my-dejanews.com
Subject: Process uses too much memory.
Message-Id: <7ak5b7$t1j$1@nnrp1.dejanews.com>
I'm having trouble with my perl process bloating to >200M and it
really shouldn't be. I wrote a perl program to process large files
(up to 400M each). Each file is broken up into records. Once every
10-10000 records, I hit a record in the file which signals me to
output some sort of summary and undef all arrays and hashes.
Nevertheless, the process sometimes exceeds 200M in runtime size,
where I would expect 10M to be sufficient, 50M tops.
I checked for silly things like
$x=pick_some_big_number();
$a[$x]=0;
Also, I don't create circular references.
I'd appreciate any clues for tracking down a "memory leak" of my own
doing, or statements of the form "perl's garbage collector leaks by
design. So rewrite your program to restart periodically".
Thanks in advance for any help!
Michael Niv.
niv@remove-if-not-a-spammer.unagi.cis.upenn.edu
------------------------------------------------------------------------------
% perl -v
This is perl, version 5.003 with EMBED
built under solaris at Nov 2 1996 11:18:11
+ suidperl security patch
Copyright 1987-1996, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
% uname -a
SunOS dali 5.6 Generic sun4u sparc SUNW,Ultra-Enterprise
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 19 Feb 1999 17:34:25 GMT
From: cybear_x[nospam]@geocities.com (Cybernetic Bear)
Subject: removing HTML tags froma file
Message-Id: <36cda040.75669693@news.webhart.net>
I want to convert HTML files to simple text files. Is there a way to
find and remove the HTML tags within PERL?
Thanks
Dave
------------------------------
Date: Fri, 19 Feb 1999 10:59:10 -0600
From: Tom Briles <tbriles@austin.ibm.com>
Subject: Re: returnvalue from system()
Message-Id: <36CD985E.66348901@austin.ibm.com>
jesper@ad.se wrote:
> Does anybody know why the returnvalue from a system() call is left-shifted 8
> bits? What's the reason for doing this?
>
> regards
>
> Jesper
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
It's actually the ReturnValue from the wait system call.
See wait.h (on a POSIX system) for a description of what else you can get out
of it.
- Tom
------------------------------
Date: Fri, 19 Feb 1999 12:41:04 -0500
From: Dan Boorstein <dboorstein@ixl.com>
Subject: Re: returnvalue from system()
Message-Id: <36CDA230.D7DB65BB@ixl.com>
Tom Christiansen wrote:
>
[SNIP]
> --
> There ain't nothin' in this world that's worth being a snot over.
> --Larry Wall in <1992Aug19.041614.6963@netlabs.com>
It makes me laugh when I see this quote pop up in Tom's signature.
chortle-chortle,
dan
------------------------------
Date: 19 Feb 1999 08:00:03 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: SRC: fwdport -- act as proxy forwarder for dedicated services
Message-Id: <36cd7c73@csnews>
Imagine that you're nestled deep inside a protective firewall.
Somewhere in the outside world is a server that you'd like access to,
but only processes on the firewall can reach it. You don't want to
login to the firewall machine each time to access that service.
For example, you might invoke it this way:
% fwdport -s nntp -l fw.oursite.com -r news.bigorg.com
Here's another example:
% fwdport -l myname:9191 -r news.bigorg.com:nntp
This time we listen for local connections on port 9191 of the host
`myname', and patch those connecting clients to the remote server
`news.bigorg.com' on its NNTP port.
--tom
#!/usr/bin/perl -w
# fwdport -- act as proxy forwarder for dedicated services
use strict; # require declarations
use Getopt::Long; # for option processing
use Net::hostent; # by-name interface for host info
use IO::Socket; # for creating server and client sockets
use POSIX ":sys_wait_h"; # for reaping our dead children
my (
%Children, # hash of outstanding child processes
$REMOTE, # whom we connect to on the outside
$LOCAL, # where we listen to on the inside
$SERVICE, # our service name or port number
$proxy_server, # the socket we accept() from
$ME, # basename of this program
);
($ME = $0) =~ s,.*/,,; # retain just basename of script name
check_args(); # processing switches
start_proxy(); # launch our own server
service_clients(); # wait for incoming
die "NOT REACHED"; # you can't get here from there
# process command line switches using the extended
# version of the getopts library.
sub check_args {
GetOptions(
"remote=s" => \$REMOTE,
"local=s" => \$LOCAL,
"service=s" => \$SERVICE,
) or die <<EOUSAGE;
usage: $0 [ --remote host ] [ --local interface ] [ --service service ]
EOUSAGE
die "Need remote" unless $REMOTE;
die "Need local or service" unless $LOCAL || $SERVICE;
}
# begin our server
sub start_proxy {
my @proxy_server_config = (
Proto => 'tcp',
Reuse => 1,
Listen => SOMAXCONN,
);
push @proxy_server_config, LocalPort => $SERVICE if $SERVICE;
push @proxy_server_config, LocalAddr => $LOCAL if $LOCAL;
$proxy_server = IO::Socket::INET->new(@proxy_server_config)
or die "can't create proxy server: $@";
print "[Proxy server on ", ($LOCAL || $SERVICE), " initialized.]\n";
}
sub service_clients {
my (
$local_client, # someone internal wanting out
$lc_info, # local client's name/port information
$remote_server, # the socket for escaping out
@rs_config, # temp array for remote socket options
$rs_info, # remote server's name/port information
$kidpid, # spawned child for each connection
);
$SIG{CHLD} = \&REAPER; # harvest the moribund
accepting();
# an accepted connection here means someone inside wants out
while ($local_client = $proxy_server->accept()) {
$lc_info = peerinfo($local_client);
set_state("servicing local $lc_info");
printf "[Connect from $lc_info]\n";
@rs_config = (
Proto => 'tcp',
PeerAddr => $REMOTE,
);
push(@rs_config, PeerPort => $SERVICE) if $SERVICE;
print "[Connecting to $REMOTE...";
set_state("connecting to $REMOTE"); # see below
$remote_server = IO::Socket::INET->new(@rs_config)
or die "remote server: $@";
print "done]\n";
$rs_info = peerinfo($remote_server);
set_state("connected to $rs_info");
$kidpid = fork();
die "Cannot fork" unless defined $kidpid;
if ($kidpid) {
$Children{$kidpid} = time(); # remember his start time
close $remote_server; # no use to master
close $local_client; # likewise
next; # go get another client
}
# at this point, we are the forked child process dedicated
# to the incoming client. but we want a twin to make i/o
# easier.
close $proxy_server; # no use to slave
$kidpid = fork();
die "Cannot fork" unless defined $kidpid;
# now each twin sits around and ferries lines of data.
# see how simple the algorithm is when you can have
# multiple threads of control?
# this is the fork's parent, the master's child
if ($kidpid) {
set_state("$rs_info --> $lc_info");
select($local_client); $| = 1;
print while <$remote_server>;
kill('TERM', $kidpid); # kill my twin cause we're done
}
# this is the fork's child, the master's grandchild
else {
set_state("$rs_info <-- $lc_info");
select($remote_server); $| = 1;
print while <$local_client>;
kill('TERM', getppid()); # kill my twin cause we're done
}
exit; # whoever's still alive bites it
} continue {
accepting();
}
}
# helper function to produce a nice string in the form HOST:PORT
sub peerinfo {
my $sock = shift;
my $hostinfo = gethostbyaddr($sock->peeraddr);
return sprintf("%s:%s",
$hostinfo->name || $sock->peerhost,
$sock->peerport);
}
# reset our $0, which on some systems make "ps" report
# something interesting: the string we set $0 to!
sub set_state { $0 = "$ME [@_]" }
# helper function to call set_state
sub accepting {
set_state("accepting proxy for " . ($REMOTE || $SERVICE));
}
# somebody just died. keep harvesting the dead until
# we run out of them. check how long they ran.
sub REAPER {
my $child;
my $start;
while (($child = waitpid(-1,WNOHANG)) > 0) {
if ($start = $Children{$child}) {
my $runtime = time() - $start;
printf "Child $child ran %dm%ss\n",
$runtime / 60, $runtime % 60;
delete $Children{$child};
} else {
print "Bizarre kid $child exited $?\n";
}
}
# If I had to choose between System V and 4.2, I'd resign. --Peter Honeyman
$SIG{CHLD} = \&REAPER;
};
__END__
--
#else /* !STDSTDIO */ /* The big, slow, and stupid way */
--Larry Wall in str.c from the 4.0 perl source code
------------------------------
Date: Thu, 18 Feb 1999 10:47:34 -0500
From: Steve Miles <smiles@wfubmc.edu>
Subject: tie complex data in DBM files
Message-Id: <36CC3616.F7E68B13@wfubmc.edu>
Hi,
I'm been working with fairly complex hashes containing hashes and
arrays, but I then tried to implement these same structures and store
them using DBM files and none of the complex structures appear to be
saved.
While I can :
push (@{ $hash{$data} }, $newdata);
and print "@{ $hash{$data}";
if I tie it to a DBM file I just get a "ARRAY(8x80s8x7)" when I reopen
the database and
print "@{ $hash{$data}";.
Any suggestions?
Steve
--------------------------------------------------------
Steve Miles (smiles@wfubmc.edu)
Wake Forest University School of Medicine
5019 Hanes, Medical Center Blvd.
Winston-Salem, NC 27157
Phone: 336.716.0454 FAX: 336.716.7200
--------------------------------------------------------
------------------------------
Date: Fri, 19 Feb 1999 09:41:12 -0800
From: samc@empirewest.com (Sam Curren)
Subject: Re: tie complex data in DBM files
Message-Id: <MPG.113742188052f9269896e0@news.sonic.net>
Yes. Because complex hash structures are stored as refrences, not the
actual data, it stores the current locations, or references.
Some ways to get around this:
1. Use MLDBM for a database format, which will store the complex hash
structure.
2. Use a simple (and most likely more efficient) join method to store
more then 1 value per key. Ex:
tie %hash (...)
$hash{$key} = join( ':', qw(value1 value2 value3 value4));
#or, to store the field names as well as their values:
$hash{$key} = "Field1=Value1:Field2=Value2:etc.";
untie $hash;
rough code, but you get the idea. I've been working on this with a
friend, so if you still need some ideas, ask me.
HTH
-Sam
In article <36CC3616.F7E68B13@wfubmc.edu>, smiles@wfubmc.edu says...
> Hi,
>
> I'm been working with fairly complex hashes containing hashes and
> arrays, but I then tried to implement these same structures and store
> them using DBM files and none of the complex structures appear to be
> saved.
>
> While I can :
> push (@{ $hash{$data} }, $newdata);
> and print "@{ $hash{$data}";
>
> if I tie it to a DBM file I just get a "ARRAY(8x80s8x7)" when I reopen
> the database and
> print "@{ $hash{$data}";.
>
> Any suggestions?
> Steve
> --------------------------------------------------------
> Steve Miles (smiles@wfubmc.edu)
> Wake Forest University School of Medicine
> 5019 Hanes, Medical Center Blvd.
> Winston-Salem, NC 27157
> Phone: 336.716.0454 FAX: 336.716.7200
> --------------------------------------------------------
>
>
>
------------------------------
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 4940
**************************************