[6435] in Perl-Users-Digest
Perl-Users Digest, Issue: 60 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 6 02:15:16 1997
Date: Wed, 5 Mar 97 23:00:21 -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 Wed, 5 Mar 1997 Volume: 8 Number: 60
Today's topics:
Re: @ interpolation in string context <tchrist@mox.perl.com>
Cannot connect to www.perl.com/perl anymore. (Warren Brown)
Re: cgi file upload utility <bildun@vci.net>
Re: Filehandles and subroutines (Anthony Peacock)
for perl experts <patrick_quinn@mail.amsinc.com>
Re: Good Perl Book <rcadmus@mcmsys.com>
Help: how to control a terminal <Aurelio.Monti@italtel.it>
Re: How to spam - legitimately (Michael Shields)
i don't understand output from h2ph <winter@nevis1.nevis.columbia.edu>
LOAN <sidhu1@home.com>
Re: mathematically correct? (David Alan Black)
Re: passing hidden input from cgi to perl script <tchrist@mox.perl.com>
Re: Perl & Win 95 (Nathan V. Patwardhan)
Re: Perl -- compiled? C converter? <tchrist@mox.perl.com>
Re: PERL --> C translator? <tchrist@mox.perl.com>
Re: Perl Question (Nathan V. Patwardhan)
Perl sockets under SunOS5.5 <chchee@hercules.iti.gov.sg>
question of perl experts <patrick_quinn@mail.amsinc.com>
question regarding linking two perl files <patrick_quinn@mail.amsinc.com>
Re Help Me Please obscene poster avoiding <christop@ozinter.co.jp>
Stumped by Syntax Error!!! (Rand Simberg)
suidperl question <joer@mo.net>
Re: unix perl <--> Oracle NT / Boston area perl consult (John D Groenveld)
WANTED: SCRIPT <mau006@bangor.ac.uk>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Mar 1997 03:48:25 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: @ interpolation in string context
Message-Id: <5fleq9$b5f$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
ken@forum.swarthmore.edu (Ken Williams) writes:
:But in this case, it guessed wrong. Why
:must the complaint about "@ requires a backslash now" be so harsh, i.e why
:does it have to abort compilation instead of just printing a warning
:message?
Because the compiled code is different! It can't generate code
to put a string there and then it work when an array comes around.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Cloning is the sincerest form of flattery.
------------------------------
Date: Wed, 05 Mar 1997 17:53:10 GMT
From: warrenb@pop.kenan.com (Warren Brown)
Subject: Cannot connect to www.perl.com/perl anymore.
Message-Id: <331db1a4.423719953@news.kenan.com>
For some reason or another I can't connect to the Perl Homepage from
my companies Internet connection but I able to reach to site from my
home computer. Is this site using a port that our company's firewall
is not allowing through. I don't have problems reaching any of my
other frequently visited sites.
warren.
Warren Brown
Quality Process Engineer
Kenan System Corporation - Cambridge MA
------------------------------
Date: 6 Mar 1997 05:32:08 GMT
From: "Bill Dunn" <bildun@vci.net>
Subject: Re: cgi file upload utility
Message-Id: <01bc29e7$8a8b4b20$9181cecf@p133.bildun.com>
I have a file upload script that is based on the CGI.pm script. I found
one on the internet some time ago and had some problems with it. I didn't
like how it worked. After you uploaded something it renamed the files to
something odd. I asked for some help on the newsgroups here and finally got
it resolved. Now it uploads files to a specified directory and keeps the
filenames correct. I haven't used it too much in quite a while but I think
all it came with is the CGI.pm, a perl script and a html file. I can send
it if you want.
> Has anyone written an upload file cgi utility that can support both
> binary and text files?
>
> I am working on one in Perl, but it adds an anyone CR/LF at the
> beginning and end of some files.
------------------------------
Date: 6 Mar 1997 11:37:55 +0800
From: rastus@opera.iinet.net.au (Anthony Peacock)
Subject: Re: Filehandles and subroutines
Message-Id: <5fle6j$abc$1@opera.iinet.net.au>
Tom Harrington (tph@longhorn.uucp) wrote:
: How can I return a filehandle from a subroutine?
: I have a subroutine which does this:
: open(LOGFILE,">$logfile_name");
: I want to be able to use the subroutine like this (or something similar):
: $filehandle = &openlog(.....);
: So that $filehandle will be an indirect file handle, which would
: allow me to have statements like this in the calling function:
: print $filehandle "Log timestamp: ",$date,"\n";
: I've tried just returning the filehandle that open() creates, but it
: doesn't work, and I'm not sure why:
: return LOGFILE;
: With this and a few other semi-random things I've tried, perl -w
: tells me that the filehandle was never opened when I try to print
: from the calling function.
Yep ok - on the right track - what you need is a module called FileHandle.
Ive included some extremely bad (but working) code.
#!/usr/bin/perl -w
use FileHandle;
my $logfile = new FileHandle;
$logfile = &openlog("/tmp/testlog");
print $logfile "Testing\n";
close($logfile);
sub openlog($) {
print "Opening $_[0]\n";
open($logfile,">$_[0]") || die ("Can't open $!");
return $logfile;
}
Anway This work and should do what you want to.
Anthony
: --
: Tom Harrington ------- tph@rmii.com ------- http://rainbow.rmii.com/~tph
: "Boy, you look tough in your black leather jacket! Bring your head
: closer, I'll be the first to smack it!" -Fishbone
: -> Fractal Kit: http://rainbow.rmii.com/~tph/fractalkit/fractal.html <-
--
\||/
| @___oo
/\ /\ / (__,,,,|***************************************************
) /^\) ^\/ _) * Anthony Peacock |I speak for myself *
) /^\/ _) * Systems Administrator | Not my employer *
) _ / / _) * Competitive Foods Ltd |------------------- *
/\ )/\/ || | )_) * PH: (09) 443 4433 |I may be dumb but I *
< > |(,,) )__) * FAX: (09) 242 1073 |can drive a tractor *
|| / \)___)\ * EMAIL: rastus@iinet.net.au |- Norwegian Saying *
| \____( )___) )___***************************************************
\______(_______;;; __;;;
------------------------------
Date: Wed, 05 Mar 1997 02:50:36 +0000
From: Patrick Quinn <patrick_quinn@mail.amsinc.com>
Subject: for perl experts
Message-Id: <331CDF7C.6F15@mail.amsinc.com>
My name is Patrick Quinn and I work for American Management Systems in
Fairfax, Virginia and currently I am coding a real-time overall testing
program. I have ran into a barrier while coding my test program. I two
perl source files. A main, and a source file containing nothing but
subroutines. My question is how to have my main program calls the
subroutines not in the main program but in the second subroutine file
for both Unix and NT development. If anyone has answers to this
question, please let me by responding to this news message or by
emailing directly and patrick_quinn@mail.amsinc.com.
Thanks,
Patrick
------------------------------
Date: 5 Mar 1997 16:56:17 GMT
From: "Ray Cadmus" <rcadmus@mcmsys.com>
Subject: Re: Good Perl Book
Message-Id: <01bc2984$d5cf3640$33738ccf@cbs07>
Learning Perl by Randal Schwartz (O'Reilly)
try www.ora.com
Sigge Eriksson <sigge.eriksson@usa.net> wrote in article
<331D39E2.2976@usa.net>...
> Anyone know a good book for a Perl beginner?
>
> / Sigge Eriksson
>
------------------------------
Date: Mon, 03 Mar 1997 09:31:33 -0800
From: Aurelio Monti <Aurelio.Monti@italtel.it>
Subject: Help: how to control a terminal
Message-Id: <331B0AF5.3209@italtel.it>
Hi
Can anybody give me a hint about how to control a UNIX terminal within
a perl script.
Basically I need to write diagnostic messages always on the same line.
Thanks in advance
Aurelio Monti
------------------------------
Date: 6 Mar 1997 01:53:06 -0000
From: shields@crosslink.net (Michael Shields)
Subject: Re: How to spam - legitimately
Message-Id: <5fl822$92j$1@daedalus.crosslink.net>
In article <5fj3qg$ea8@work2.e-z.net>, tedder <tedder@e-z.net> wrote:
> Maybe this should all go to alt.english or where ever all the English
> freaks hang out :^)
alt.usage.english.
--
Shields, CrossLink.
------------------------------
Date: Wed, 05 Mar 1997 23:19:14 -0500
From: David Winter <winter@nevis1.nevis.columbia.edu>
Subject: i don't understand output from h2ph
Message-Id: <331E45C2.41C6@nevis1.nevis.columbia.edu>
oh gurus of the world of perl, could one (or more!) of you explain to me the
meaning of the following piece of code? it is taken from
/usr/lib/perl/sys/select.ph on an Irix 5.3 machine. (the version of perl is
5.003)
if (defined &_ABI_SOURCE) {
eval 'sub FD_ZERO {
local($p) = @_;
eval " &memset(( &void *)($p), 0, $sizeof{*($p}))";
}';
}
else {
eval 'sub FD_ZERO {
local($p) = @_;
eval " &bzero(($p), $sizeof{*($p}))";
}';
}
namely, what is going on with the "( &void *)" piece? and what about the
"$sizeof{*($p}))" part? to my untrained eyes, it seems that the braces and
parens are out of order, and i am amazed that the thing compiles.
in fact, that is why it caught my attention. in the process of porting my
scripts to an alpha machine, they would no longer compile, with perl screaming
about the line involving the bzero subroutine call.
on the sgi machine, i am assuming that the file was generated using h2ph and
nothing else. this assumption follows from that fact that i DO know (i watched
over the shoulder) that it was generated using h2ph (and nothing else) on the
alpha machine -- and they are pretty much the same.
thanks -
dave
---------------------------- Dave ------------------------------------
Columbia University Nevis Laboratories
City of New York Irvington, NY
Phone: 212-854-3366 Phone: 914-591-2836
Fax: 212-854-33?? Fax: 914-591-8120
WWW: http://nevis1.columbia.edu/~winter
Experiment 910 at the AGS: "Searching for a strange particle in an even
stranger land."
------------------------------
Date: 6 Mar 1997 06:06:11 GMT
From: "SIDHU" <sidhu1@home.com>
Subject: LOAN
Message-Id: <01bc29f4$7d7f8740$f0420118@C1000075-A.frmt1.sfba.home.com>
I need a scrip that takes a monthly income and can tell me how much loan i
can have. This is for a project. Real Estate type.
------------------------------
Date: 5 Mar 1997 20:28:30 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: mathematically correct?
Message-Id: <5fkl1e$o30@pirate.shu.edu>
Hello -
tloser@valdemar.microserve.com (Thomas A. Loser) writes:
> The PERL (camel) book gives an example for selecting a random line
>from a file of unknown length with a single pass through the file:
> (paraphrased from page 246)
> "This procedure selects a line at random from a file, using just
>one pass over the file and without knowing in advance the number of
>lines. It works by calculating the probability that the current line
>would be selected with a probability of 100%, but the second line
>has a 50% chance of replacing the first one, the third line a 33%
>chance of replacing one of the first two, and so on."
> srand;
> rand($.) < 1 && ($it = $_) while <>;
>
> I'm no math genius but if I assume just 3 lines it appears that line
>2 will replace line 1 once every other time (1 out of 2) and line 3
>will replace 1 *or* 2 every third time (1 out of 3) leaving line 1 as
>the selected line just 1 out of every six times. (1/2 + 1/3 = 5/6
>chance of line 1 being replaced). Is my logic faulty or does this
>routine heavily favor lines later in the file? I'm attracted to its
>simplicity but not if it's way skewed.
Half the time, line 1 will be knocked out by line 2.
One-third of the *remaining* times (i.e., one-sixth of all times)
line 1 will be knocked out by line 3.
So line 1's chances of being eliminated are
( (1/2) + (1/2 * 1/3) ) = 2/3.
In other words, even though line 1 is vulnerable from line 2, line 2
also absorbs half of line 1's total risk from line 3. Or: by
surviving line 2, line 1 then gets 2-to-1 odds against line three
(which, since it only happens half the time, is like 1-to-1 odds
overall).
David Black
dblack@icarus.shu.edu
------------------------------
Date: 6 Mar 1997 03:56:46 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: passing hidden input from cgi to perl script
Message-Id: <5flf9u$b5f$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
futurecard@netstorage.com writes:
:I want to pass the date to a perl script. I thought about doing it like
:this:
:(html cgi form)
:<input type="hidden" name="date" value="$today">
:
:Of course I would declare the variable $today=`/bin/date +%m/%d/%Y`
:in the perl. This does not work. I get the literal "$today" as a
:result.
:What is the proper way to do this using the 'hidden' input.
The proper way is to use the CGI module, which does this all for you.
It's just *made* for such things.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Just because you're screwed *up* doesn't mean your screwed." --Larry Wall
------------------------------
Date: 6 Mar 1997 02:45:40 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl & Win 95
Message-Id: <5flb4k$otb@fridge-nf0.shore.net>
Kevin A. Miller (kmiller@mail.cheta.net) wrote:
: Someone please help; I am looking for Perl5 that will run on my P-166
: system using Win95. I have tried to use Perl for Win32 from various
http://www.activeware.com
Get perl5.003_07 - the Intel binary, NOT the source NOR PerlScript.
--
Nathan V. Patwardhan
nvp@shore.net
"What is your quest?"
------------------------------
Date: 6 Mar 1997 03:33:31 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl -- compiled? C converter?
Message-Id: <5fldub$b5f$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
jgoerzen@happy.cs.twsu.edu (John Goerzen) writes:
:Hello,
:
:On page XII of the preface in Wall's "camel book" (Programming Perl, 2nd
:ed.), he mentions that "[Perl] passes off the intermediate code to the
:interpreter to execute (or optionally to any of several modular back ends
:that can emit C or bytecode.)"
:
:I am not sure what this "bytecode" is (is it executable?)
:
:In any case, I am very interested in the C code. I checked the PERL FAQ at
:www.perl.com and it stated that there was no way to make C code from Perl.
:Yet Wall's book seems to indicate that just that thing is possible. I would
:obviously tend to believe the book over the FAQ :-)
:
:So...where can I find this sort of thing?
>From the FAQ yet to be published:
=head2 What is undump?
See the next questions.
=head2 How can I make my Perl program run faster?
The best way to do this is to come up with a better algorithm.
This can often make a dramatic difference. Chapter 8 in the Camel
has some efficiency tips in it you might want to look at.
Other approaches include autoloading seldom-used Perl code. See the
AutoSplit and AutoLoader modules in the standard distribution for
that. Or you could locate the bottleneck and think about writing just
that part in C, the way we used to take bottlenecks in C code and
write them in assembler.
In some cases, it may be worth it to use the backend compiler to
produce byte code (saving compilation time) or compile into C, which
will certainly save compilation time and sometimes a small amount (but
not much) execution time. See the question the compiling your Perl
programs.
If you're currently linking your perl executable to a shared libc.so,
you can often gain a 10-25% performance benefit by rebuilding it to
link with a static libc.a instead. This will make a bigger perl
executable, but your Perl programs (and programmers) may thank you for
it. See the F<INSTALL> file in the source distribution for more
information.
Unsubstantiated reports allege that perl interpreters that use sfio
outperform those that don't (for IO intensive applications). To try
this, see the F<INSTALL> file in the source distribution, especially
the "Selecting File IO mechanisms" section.
The undump program was an old attempt to speed up your Perl program
by storing the already-compiled form to disk. This is no longer
a viable option, as it only worked on a few architectures, and
wasn't a good solution anyway.
=head2 How can I make my Perl program take less memory?
When it comes to time-space tradeoffs, Perl nearly always prefers to
throw memory at a problem. Scalars in Perl use more memory than
strings in C, arrays take more that, and hashes use even more. While
there's still a lot to be done, recent releases have been addressing
these issues. For example, as of 5.004, duplicate hash keys are
shared amongst all hashes using them, so require no reallocation.
In some cases, using substr() or vec() to simulate arrays can be
highly beneficial. For example, an array of a thousand booleans will
take at least 20,000 bytes of space, but it can be turned into one
125-byte bit vector for a considerable memory savings. The standard
Tie::SubstrHash module can also help for certain types of data
structure.
Another thing to try is learning whether your Perl was compiled with
the system malloc or with Perl's built-in malloc. Whichever one it
is, try using the other one and see whether this makes a difference.
Information about malloc is in the F<INSTALL> file in the source
distribution. You can find out whether you are using perl's malloc by
typing perl -V:usemymalloc.
=head2 How can I free an array or hash so my program shrinks?
You can't. Memory the system once allocates to a problem will
never be returned to the system. That's why long-running programs
sometimes re-exec themselves.
However, judicious use of my() on your variables will help make sure
that they go out of scope so that Perl can free up their storage for
use in other parts of your program. (NB: my() variables also execute
about 10% faster than globals.) A global variable, of course, never
goes out of scope, so you can't get its space automatically reclaimed,
although undef()ing it will achieve the same effect. In general,
memory allocation and de-allocation isn't something you can or should
be worrying about much in Perl.
=head2 How can I make my CGI script more efficient?
Beyond the normal measures described to make general Perl programs
faster or smaller, a CGI program has additional issues. It may be run
several times per second. Given that each time it runs it will need
to be re-compiled and will often allocate a megabyte or more of system
memory, this can be a killer. Compiling into C B<isn't going to help
you> because the process start-up overhead is where the bottleneck is.
There are at least two popular ways to avoid this overhead. One
solution involves running the Apache HTTP server (available from
http://www.apache.org/) with either of the mod_perl or mod_fastcgi
plugin modules. With mod_perl and the Apache::* modules (from CPAN),
httpd will run with an embedded Perl interpreter which pre-compiles
your script and then executes it within the same address space without
forking. The Apache extension also gives Perl access to the internal
server API, so modules written in Perl can do just about anything a
module written in C can. With the FCGI module (from CPAN), a Perl
executable compiled with sfio (see the F<INSTALL> file in the
distribution) and the mod_fastcgi module (available from
http://www.fastcgi.com/) each of your perl scripts becomes a permanent
CGI daemon processes.
Both of these solutions can have far-reaching effects on your system
and on the way you write your CGI scripts, so investigate them with
care.
=head2 How can I hide the source for my Perl program?
Delete it. :-) Seriously, there are a number of (mostly
unsatisfactory) solutions with varying levels of "security".
First of all, however, you B<can't> take away read permission, because
the source code has to be readable in order to be compiled and
interpreted. (That doesn't mean that a CGI script's source is
readable by people on the web, though.) So you have to leave the
permissions at the socially friendly 0755 level.
Some people regard this as a security problem. If your program does
insecure things, and relies on people not knowing how to exploit those
insecurities, it is often possible that someone could determine the
insecure things and exploit them without viewing the source. Security
through obscurity, the name for hiding your bugs instead of fixing
them, is little security indeed.
You can try using encryption via source filters (Filter::* from CPAN).
But they might be able to decrypt it. You can try using the byte-code
compiler and interpreter described below, but they might be able to
de-compile it. You can try using the native-code compiler described
below, but they might be able to disassemble it. These pose varying
degrees of difficulty to people wanting to get at your code, but none
can definitively conceal it (this is true of every language, not just
Perl).
If you're concerned about people profiting from your code, then the
bottom line is that nothing else but a restrictive licence will give
you legal security. License your software and pepper it with
threatening statements like "This is unpublished proprietary software
of XYZ Corp. Your access to it does not give you permission to use it
blah blah blah."
=head2 How can I compile my Perl program into byte-code or C?
Malcolm Beattie has written a multifunction backend compiler,
available from CPAN, that can do both these things. It is as of
Feb-1997 in late alpha release, which means it's fun to play with if
you're a programmer but not really for people looking for turn-key
solutions.
I<Please> understand that merely compiling into C does not in and of
itself guarantee that your code will run very much faster. That's
because except for lucky cases where a lot of native type inferencing
is possible, the normal Perl run time system is still present and thus
will still take just as long to run and be just as big. Most programs
save little more than compilation time, leaving execution no more than
10-30% faster. A few rare programs actually benefit significantly
(like several times faster), but this takes some tweaking of your
code.
Malcolm will be in charge of the 5.005 release of Perl itself
to try to unify and merge his compiler and multithreading work into
the main release.
You'll probably be astonished to learn that the current version of the
compiler generates a compiled form of your script whose executable is
just as big as the original perl executable, and then some. That's
because as currently written, all programs are prepared for a full
eval() statement. You can tremendously reduce this cost by building a
shared libperl.so library and linking against that. See the
F<INSTALL> podfile in the perl source distribution for details. If
you link your main perl binary with this, it will make it miniscule.
For example, on my system, /usr/bin/perl is only 11k in size!
--
Tom Christiansen tchrist@jhereg.perl.com
sv_magic(sv, Nullsv, 'B', Nullch, 0); /* deep magic */
--Larry Wall, from util.c in the v5.0 perl distribution
------------------------------
Date: 6 Mar 1997 03:39:45 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: PERL --> C translator?
Message-Id: <5flea1$b5f$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Kimberly Spence <kspence@pike.modes.tc.faa.gov> writes:
:I have a perl script that I want to
:convert to C. I have just downloaded
:CPAN (although the directory created
:was "B"). I am waiting for the PERL
:on my system to be updated to 5.002.
:
:In the meantime, does anyone have any
:suggestions?
I suggest you think carefully about the matter.
=head2 What is undump?
See the next questions.
=head2 How can I make my Perl program run faster?
The best way to do this is to come up with a better algorithm.
This can often make a dramatic difference. Chapter 8 in the Camel
has some efficiency tips in it you might want to look at.
Other approaches include autoloading seldom-used Perl code. See the
AutoSplit and AutoLoader modules in the standard distribution for
that. Or you could locate the bottleneck and think about writing just
that part in C, the way we used to take bottlenecks in C code and
write them in assembler.
In some cases, it may be worth it to use the backend compiler to
produce byte code (saving compilation time) or compile into C, which
will certainly save compilation time and sometimes a small amount (but
not much) execution time. See the question the compiling your Perl
programs.
If you're currently linking your perl executable to a shared libc.so,
you can often gain a 10-25% performance benefit by rebuilding it to
link with a static libc.a instead. This will make a bigger perl
executable, but your Perl programs (and programmers) may thank you for
it. See the F<INSTALL> file in the source distribution for more
information.
Unsubstantiated reports allege that perl interpreters that use sfio
outperform those that don't (for IO intensive applications). To try
this, see the F<INSTALL> file in the source distribution, especially
the "Selecting File IO mechanisms" section.
The undump program was an old attempt to speed up your Perl program
by storing the already-compiled form to disk. This is no longer
a viable option, as it only worked on a few architectures, and
wasn't a good solution anyway.
=head2 How can I make my Perl program take less memory?
When it comes to time-space tradeoffs, Perl nearly always prefers to
throw memory at a problem. Scalars in Perl use more memory than
strings in C, arrays take more that, and hashes use even more. While
there's still a lot to be done, recent releases have been addressing
these issues. For example, as of 5.004, duplicate hash keys are
shared amongst all hashes using them, so require no reallocation.
In some cases, using substr() or vec() to simulate arrays can be
highly beneficial. For example, an array of a thousand booleans will
take at least 20,000 bytes of space, but it can be turned into one
125-byte bit vector for a considerable memory savings. The standard
Tie::SubstrHash module can also help for certain types of data
structure.
Another thing to try is learning whether your Perl was compiled with
the system malloc or with Perl's built-in malloc. Whichever one it
is, try using the other one and see whether this makes a difference.
Information about malloc is in the F<INSTALL> file in the source
distribution. You can find out whether you are using perl's malloc by
typing perl -V:usemymalloc.
=head2 How can I free an array or hash so my program shrinks?
You can't. Memory the system once allocates to a problem will
never be returned to the system. That's why long-running programs
sometimes re-exec themselves.
However, judicious use of my() on your variables will help make sure
that they go out of scope so that Perl can free up their storage for
use in other parts of your program. (NB: my() variables also execute
about 10% faster than globals.) A global variable, of course, never
goes out of scope, so you can't get its space automatically reclaimed,
although undef()ing it will achieve the same effect. In general,
memory allocation and de-allocation isn't something you can or should
be worrying about much in Perl.
=head2 How can I make my CGI script more efficient?
Beyond the normal measures described to make general Perl programs
faster or smaller, a CGI program has additional issues. It may be run
several times per second. Given that each time it runs it will need
to be re-compiled and will often allocate a megabyte or more of system
memory, this can be a killer. Compiling into C B<isn't going to help
you> because the process start-up overhead is where the bottleneck is.
There are at least two popular ways to avoid this overhead. One
solution involves running the Apache HTTP server (available from
http://www.apache.org/) with either of the mod_perl or mod_fastcgi
plugin modules. With mod_perl and the Apache::* modules (from CPAN),
httpd will run with an embedded Perl interpreter which pre-compiles
your script and then executes it within the same address space without
forking. The Apache extension also gives Perl access to the internal
server API, so modules written in Perl can do just about anything a
module written in C can. With the FCGI module (from CPAN), a Perl
executable compiled with sfio (see the F<INSTALL> file in the
distribution) and the mod_fastcgi module (available from
http://www.fastcgi.com/) each of your perl scripts becomes a permanent
CGI daemon processes.
Both of these solutions can have far-reaching effects on your system
and on the way you write your CGI scripts, so investigate them with
care.
=head2 How can I hide the source for my Perl program?
Delete it. :-) Seriously, there are a number of (mostly
unsatisfactory) solutions with varying levels of "security".
First of all, however, you B<can't> take away read permission, because
the source code has to be readable in order to be compiled and
interpreted. (That doesn't mean that a CGI script's source is
readable by people on the web, though.) So you have to leave the
permissions at the socially friendly 0755 level.
Some people regard this as a security problem. If your program does
insecure things, and relies on people not knowing how to exploit those
insecurities, it is often possible that someone could determine the
insecure things and exploit them without viewing the source. Security
through obscurity, the name for hiding your bugs instead of fixing
them, is little security indeed.
You can try using encryption via source filters (Filter::* from CPAN).
But they might be able to decrypt it. You can try using the byte-code
compiler and interpreter described below, but they might be able to
de-compile it. You can try using the native-code compiler described
below, but they might be able to disassemble it. These pose varying
degrees of difficulty to people wanting to get at your code, but none
can definitively conceal it (this is true of every language, not just
Perl).
If you're concerned about people profiting from your code, then the
bottom line is that nothing else but a restrictive licence will give
you legal security. License your software and pepper it with
threatening statements like "This is unpublished proprietary software
of XYZ Corp. Your access to it does not give you permission to use it
blah blah blah."
=head2 How can I compile my Perl program into byte-code or C?
Malcolm Beattie has written a multifunction backend compiler,
available from CPAN, that can do both these things. It is as of
Feb-1997 in late alpha release, which means it's fun to play with if
you're a programmer but not really for people looking for turn-key
solutions.
I<Please> understand that merely compiling into C does not in and of
itself guarantee that your code will run very much faster. That's
because except for lucky cases where a lot of native type inferencing
is possible, the normal Perl run time system is still present and thus
will still take just as long to run and be just as big. Most programs
save little more than compilation time, leaving execution no more than
10-30% faster. A few rare programs actually benefit significantly
(like several times faster), but this takes some tweaking of your
code.
Malcolm will be in charge of the 5.005 release of Perl itself
to try to unify and merge his compiler and multithreading work into
the main release.
You'll probably be astonished to learn that the current version of the
compiler generates a compiled form of your script whose executable is
just as big as the original perl executable, and then some. That's
because as currently written, all programs are prepared for a full
eval() statement. You can tremendously reduce this cost by building a
shared libperl.so library and linking against that. See the
F<INSTALL> podfile in the perl source distribution for details. If
you link your main perl binary with this, it will make it miniscule.
For example, on my system, /usr/bin/perl is only 11k in size!
--
Tom Christiansen tchrist@jhereg.perl.com
if (rsfp = mypopen("/bin/mail root","w")) { /* heh, heh */
--Larry Wall in perl.c from the perl source code
------------------------------
Date: 6 Mar 1997 02:49:26 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl Question
Message-Id: <5flbbm$otb@fridge-nf0.shore.net>
Rohit Sherman (rohit@ebs330.eb.uah.edu) wrote:
: My question is:
: What is the purpose of salt in crypt function usage. How does it work ?
It encrypts the clear text against the value of the salt. You might do
some 'net searching for crypt() for better details!
For example
$salt = 'foo';
$word = 'mine';
crypt($word, $salt);
Would give different results than:
$salt = 'pleas493';
$word = 'mine';
crypt($word, $salt);
OR this gives troublesome results:
$salt = 'mine';
$word = 'mine';
crypt($word, $salt);
--
Nathan V. Patwardhan
nvp@shore.net
"What is your quest?"
------------------------------
Date: Thu, 6 Mar 1997 11:09:27 +0800
From: Benny Chee <chchee@hercules.iti.gov.sg>
Subject: Perl sockets under SunOS5.5
Message-Id: <Pine.SOL.3.91.970306110555.23455A-100000@hercules.iti.gov.sg>
Hi,
I have just written a perl socket in IRIX5.3, so, due to
the firewall in company, i port it over to a SUN machine.
So, i did the usual stuff, copy and paste the script to the
Sun...
And i got a new error msg :
The errors are :
Unsupported socket function "getprotobyname" called at fetch.pl line 56
(#1)
(F) Your machine doesn't support the Berkeley socket mechanism, or at
least that's what Configure thought.
Uncaught exception from user code:
Unsupported socket function "getprotobyname" called at fetch.pl
line 56.
main::setsocket called at fetch.pl line 7
It seems to me that the getprotobyname function is not present in this
SunOS Release 5.5.
So, i replace the getprotobyname with the number 6 <-the proto
number.
And i had more error :
Unsupported socket function "socket" called at fetch.pl line 57 (#1)
(F) Your machine doesn't support the Berkeley socket mechanism, or at
least that's what Configure thought.
Uncaught exception from user code:
Unsupported socket function "socket" called at fetch.pl line 57.
main::setsocket called at fetch.pl line 7
Can anybody explain, what's this msg all about?
Thks.
Benny Chee :) | "I used to have a life,
chchee@iti.gov.sg | but now I have a modem."
------------------------------
Date: Wed, 05 Mar 1997 02:44:13 +0000
From: Patrick Quinn <patrick_quinn@mail.amsinc.com>
Subject: question of perl experts
Message-Id: <331CDDFD.139C@mail.amsinc.com>
My name is Patrick Quinn and I work for American Management Systems in
Fairfax, Virginia and currently I am coding a real-time overall testing
program. I have ran into a barrier while coding my test program. I two
perl source files. A main, and a source file containing nothing but
subroutines. My question is how to have my main program calls the
subroutines not in the main program but in the second subroutine file
for both Unix and NT development. If anyone has answers to this
question, please let me by responding to this news message or by
emailing directly and patrick_quinn@mail.amsinc.com.
Thanks,
Patrick Quinn
------------------------------
Date: Wed, 05 Mar 1997 02:29:45 +0000
From: Patrick Quinn <patrick_quinn@mail.amsinc.com>
Subject: question regarding linking two perl files
Message-Id: <331CDA99.5ED5@mail.amsinc.com>
My name is Patrick Quinn and I work for American Management Systems in
Fairfax, Virginia and currently I am coding a real-time overall testing
program. I have ran into a barrier while coding my test program. I two
perl source files. A main, and a source file containing nothing but
subroutines. My question is how to have my main program calls the
subroutines not in the main program but in the second subroutine file
for both Unix and NT development. If anyone has answers to this
question, please let me by responding to this news message or by
emailing directly and patrick_quinn@mail.amsinc.com.
Thanks,
Patrick
------------------------------
Date: Thu, 06 Mar 1997 15:35:15 +0900
From: "christop@ozinter.co.jp" <christop@ozinter.co.jp>
Subject: Re Help Me Please obscene poster avoiding
Message-Id: <331E65A3.2A1A@ozinter.co.jp>
> I'm trying to learn enough perl to modify a script called WWWBoard (by
> Matt Wright, who I've tried to contact -- unsuccessfully) in order to
> hide any/all obtainable user info in the posted messages, to try to help
> catch anonymous posters of obscene msgs.
Sorry - I can't find the original message in my newsfeed only on
altavista so I requote here..
The way I get round this is to use Selena Sol's mailing list manager to
make the board subscription only. Just using authentication allows
people to subscribe with fake email addresses - we require that someone
hits the subscribe button to get the passwords emailed to them. If it
turns out they're being naughty and not playing by the rules then we add
their email to a bad_list. When the subscribe button is pressed if the
email submitted matches one in the badlist then an "Internal
Misconfiguration Error" is given.. Every so often (ie after an
"offender" incident) we change the passwords and mass mail to everyone
on the board the new passwords and username to get in. Works great.
If anyone has a more elegant solution I'd be dead happy to read it
though.
Christopher
http://www.wonderlandinorbit.com
------------------------------
Date: Thu, 06 Mar 1997 05:16:53 GMT
From: simberg@interglobal.org (Rand Simberg)
Subject: Stumped by Syntax Error!!!
Message-Id: <331e5092.21104707@nntp.ix.netcom.com>
Can anyone see what's wrong with this piece of code? I pulled it out
of a script that parses fine without it, but when I add it in, I get a
syntax error at the end, as noted in the comment. To make it even
more mysterious, my Windows Perl (activeware's) says that it's OK, but
when I run perl -c on my web server, I get a syntax error at line x,
where x corresponds to the file closure. I've tried running it with
diagnostics to get more info, but the server I'm running it on (it's
for a client that I'm developing a site for) says that it can't find
the diagnostics library. Any ideas?!
Most gratefully, TIA...
###############################################
sub update_wishfile {
local($wish_file) = @_;
open(WISH, "+<../www/data/$wish_file") || die "Can't open wish file!";
flock(WISH, 2);
@wish = <WISH>;
seek(WISH, 0, 0);
truncate(WISH, 0);
foreach $wishline (@wish) { #7
if ($wishline =~ /$rec_name/) { #6
($id,$data,$prefs,$wishdata,$granted) = split(/\&/, $wishline);
@wishes = split(/\*/, $wishdata);
$wishline = "$id\&$data\&$prefs\&";
foreach $choice (@choices) { #8
#If it isn't the userid
if ($choice =~ /\|/) { #2
#Split it into the product number, choice number, and number ordered
($pnum,$piece,$amt) = split(/\|/,$choice);
#And check against each wish...
foreach $wish (@wishes) { #9
($wpnum,$wpiece,$wamt) = split(/\|/, $wish);
if (($wpnum eq $pnum) && ($piece eq $wpiece)) { #10
$wamt = $wamt - $amt;
if ($wamt > 0) { #12
$wishline .= "$wpnum|$wpiece|$wamt*";
} #12
$granted .= "$choice*";
} #10
else { #11
$wishline .= $wish;
} #11
} #9
} #2
} #8
print WISH "$wishline\&$granted\n";
} #6
else { #13
print WISH "$wishline\n";
} #13
} 7#
############Syntax Error Shows Up Right Here!!!!
close(WISH);
} #update_wishfile
************************************************************************
simberg@interglobal.org * 310 372-7963 (CA) 307 739-1296 (Jackson Hole)
interglobal space lines * 307 733-1391 (Fax) http://www.interglobal.org
"Extraordinary launch vehicles require extraordinary markets..."
------------------------------
Date: Wed, 05 Mar 1997 14:26:45 -0800
From: Joe Rabinoff <joer@mo.net>
Subject: suidperl question
Message-Id: <331DF325.41C6@mo.net>
Okay here's the problem.
I have a perl script that I want to suid to a normal user. This is no
problem, except that it's really easy to hack a server if you have
suidperl enabled, so the webmaster has disabled it, and will only enable
it again if there is some way to make it so suidperl will not allow
suids to root. Does anybody know if ther's a way to do this? Otherwise
I have to rewrite it in C...
Thanks,
Joe Rabinoff
------------------------------
Date: 5 Mar 1997 22:30:41 -0500
From: groenvel@tholian.cse.psu.edu (John D Groenveld)
Subject: Re: unix perl <--> Oracle NT / Boston area perl consultants?
Message-Id: <5fldp1$p37@tholian.cse.psu.edu>
In article <857578048.10086@dejanews.com>, <cdagdigian@genetics.com> wrote:
>Any recomendations or pointers to resources that deal with using perl to
>communicate with Oracle *across a network* would be greatly appreciated.
The easiest solution would be to use Oracle SQLNet between your application
server and database. You'll have to contact your Oracle sales rep for more
info.
John
groenvel@cse.psu.edu
------------------------------
Date: Wed, 05 Mar 1997 18:32:01 +0000
From: "G.Cheers" <mau006@bangor.ac.uk>
Subject: WANTED: SCRIPT
Message-Id: <331DBC21.6F72@bangor.ac.uk>
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
I want a script written in Perl that allows other Webmasters to register
a link from their site to mine.
The purpose of this is so that I can display the top 25 referrals to my
site on a seperate page.
I also want to be able to allow each registree to view their account
on-line. This will give them details of the amount of referrals they
have provided my site with and the amount that they have received in
return from the referrals page.
IMPORTANT: It would be nice if only 'real' referrals were logged, that
is preventing registrees from referring their own sites over and over
again in order to get further up the list. There may also be a
possibility in the future of registrees being paid for each referral, so
I would prefer it if certain security measures were taken in order to
prevent fraudulant referrals.
Any other features or ideas that would make for a better package are
appreciated.
Well that's the basis of it anyway.
G. Cheers
mau006@bangor.ac.uk
E-mail Appreciated
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
------------------------------
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 60
************************************