[26416] in Perl-Users-Digest
Perl-Users Digest, Issue: 8587 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 30 06:05:31 2005
Date: Sun, 30 Oct 2005 03:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 30 Oct 2005 Volume: 10 Number: 8587
Today's topics:
FAQ 8.49 How do I add a directory to my include path (@ <comdog@pair.com>
FAQ 9.24 How do I fetch a news article or the active ne <comdog@pair.com>
Re: How to get the exact path of a script <peter@berghold.net>
Re: Performance & Perl <tassilo.von.parseval@rwth-aachen.de>
RTF and UTF-8 files in Perl <VSRawat@Invalid.none>
Re: Web form CGI, Security? <peter@berghold.net>
Re: why the perl docs suck <peter@berghold.net>
Re: windows program return values vs perl return values <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 30 Oct 2005 04:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 8.49 How do I add a directory to my include path (@INC) at runtime?
Message-Id: <dk1gll$fsu$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
8.49: How do I add a directory to my include path (@INC) at runtime?
Here are the suggested ways of modifying your include path:
the PERLLIB environment variable
the PERL5LIB environment variable
the perl -Idir command line flag
the use lib pragma, as in
use lib "$ENV{HOME}/myown_perllib";
The latter is particularly useful because it knows about machine
dependent architectures. The lib.pm pragmatic module was first included
with the 5.002 release of Perl.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sun, 30 Oct 2005 11:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 9.24 How do I fetch a news article or the active newsgroups?
Message-Id: <dk2995$ccl$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
9.24: How do I fetch a news article or the active newsgroups?
Use the Net::NNTP or News::NNTPClient modules, both available from CPAN.
This can make tasks like fetching the newsgroup list as simple as
perl -MNews::NNTPClient
-e 'print News::NNTPClient->new->list("newsgroups")'
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sat, 29 Oct 2005 23:05:41 -0400
From: "Peter L. Berghold" <peter@berghold.net>
Subject: Re: How to get the exact path of a script
Message-Id: <43643888$0$6459$9a6e19ea@unlimited.newshosting.com>
vikrant@saysnetsoft.com wrote:
>
>
> Now,what i want to do is to find the above path means where
> my script(example.pl) store or currently exists when i run
> my script(example.pl) in the following different ways:-
>
>
use FindBin;
This is part of the Perl core. Check it out.
--
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Peter L. Berghold Peter@Berghold.Net
"Those who fail to learn from history are condemned to repeat it."
AIM: redcowdawg Yahoo IM: blue_cowdawg ICQ: 11455958
------------------------------
Date: Sun, 30 Oct 2005 08:23:53 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Performance & Perl
Message-Id: <3sjaobFoj651U1@news.dfncis.de>
Also sprach robic0@yahoo.com:
> Or C?
>
> (Disclaimer: I have not delved into the Perl source)
>
> How close does Perl follow C as far as primatives?
Sometimes closely, but more often it doesn't follow C at all.
Some operators are implemented in terms of their C counterparts (most
notably all the bitwise operators).
The biggest differences are probably with arrays (that resize
dynamically) and strings. Perl strings are implemented on top of C
char-pointers and yet are infinitely smarter than C strings (e.g. they
transparently morph from one encoding into the other, ideally with the
programmer not even noticing it).
And there are of course hash-tables, something that C doesn't have at
all.
> Can I rely on Perl language constructs to follow C when
> writing performance code?
Some generic wisdom can probably be applied to writing both C and Perl
code. One such rule is to avoid the copying around of data although it's
sometimes not obvious what Perl code will result in a copy.
One difference for example is how C and Perl handle structures. One
common consideration with C is the order of struct-members that has an
impact both on memory consumption and performance due to memory
alignment issues:
struct A {
char a;
int32_t b;
char c[3];
}; /* 12 bytes on machines that align on 4-byte boundaries */
struct B {
char a;
char c[3];
int32_t b;
}; /* only 8 bytes */
In Perl, hashes are ordinarily used for modelling structs. They have
very different characteristics. One is that access to the members is
resolved at runtime whereas the members of a C structure have a fixed
memory offset from the base address which the compiler knows about.
On the other hand, certain C constructs might end up being faster in
Perl. Perl's index() is likely to be faster than C's strstr() as it uses
Boyer-Moore on the inside and attaches these information to the
variable.
Likewise length() versus strlen(): Perl's length() happens in constant
time as the length of each string is stored in the underlying
data-structure. C on the other hand has to loop over each character to
find the terminating '\0'.
Another thing to keep in mind is that function calls in Perl are slow.
In C they are also slower than inlined code, but with Perl the penalty
is by an order of a few magnitudes more severe. It's even worse with
method calls as the resolution of every method happens at runtime
(although perl does cache the information). In C++ method dispatch can
often by figured out at compile-time unless it's dynamic dispatch. Perl
only has dynamic dispatch.
I believe the best way to improve the performance of Perl programs is by
using the Benchmark module to find out which of the conceivable versions
performs better.
> In a runtime race will a Perl for loop time exactly the same as a
> C for loop? When the race begins, if not, why not?
The C loop wins. But then the Perl for-loop is more than just a loop:
It's a generic iterator construct that iterates over any list-alike
thing.
> Any divergence in stack processing Perl to C?
Perl only uses the stack for passing arguments to and from functions and
methods. Unlike in C, it has a variadic size. That's why Perl functions
don't need a prototype. And if they have a prototype, it's for an
entirely different purpose.
> Is there such a thing as a Perl "temporary" on the stack?
Perl knows about temporaries but they are not created on the stack but
instead on a separate thing called a scratchpad of which each block gets
its own. These temporaries aren't blindly destroyed when the block is
left. Instead, their reference-count is decremented. In the below
$temporary isn't freed because set_tmp() and get_tmp() still reference
it in their bodies. That means Perl has real closures:
{
my $temporary;
sub set_tmp { $temporary = shift; }
sub get_tmp { return $temporary; }
}
set_tmp 42;
print get_tmp;
> Why would I need to care about any of this on a "higher level"
> language, or is Perl a higher level language?
Perl is a higher level language because you never have to worry about
any of those menial tasks that a C programmer constantly needs to be
aware of. That comes at a price so a Perl program can easily be 50 times
slower than a well-written C equivalent.
But there are ways to couple the convenience of Perl with the
performance of C. Many modules on the CPAN were written in C or C++ (or
rather in a dialect called XS which facilitates the passing of data from
Perl to C and vice versa). There is also Inline::C.
Toying around with any of these is an excellent and fun way to learn
about the inner workings of Perl because you'll inevitably learn how the
Perl stack works, how Perl's reference-counting is used to do
garbage-collection, how Perl's primitive data-types work and so on and
so forth.
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: 30 Oct 2005 10:38:08 +0100
From: "V S Rawat" <VSRawat@Invalid.none>
Subject: RTF and UTF-8 files in Perl
Message-Id: <xn0e93zst5r39c000@xananews>
1. How do I open a RTF file as input in Perl and read formatted
ASCII text from it?
2. How do I open a UTF-8 (Unicode) file as output in Perl and
write Unicode text to it?
--
Thanks and Regards.
------------------------------
Date: Sat, 29 Oct 2005 22:48:32 -0400
From: "Peter L. Berghold" <peter@berghold.net>
Subject: Re: Web form CGI, Security?
Message-Id: <43643484$0$6449$9a6e19ea@unlimited.newshosting.com>
one man army wrote:
> I would like to generate a few simple web forms. Is the Perl CGI, and a
> cgi-enabled directory, a huge security hole?
>
Is a door on a house a huge security hole? It is if you leave the door
unlocked.
> I read the lines that say to disable upload, and limit the size of a
> POST.
>
If you don't understand the implications of doing uploads... don't do them.
> I'm asking my host to install CGI, although I know he is security
> conscious.
>
Again... understand the implications of what you are asking your hosting
facility to do this. The reason a lot of hosting facilities don't allow
CGI is because folks don't know what they are doing.
On the other hand I can think of all sorts of ways I could set up a
virtual server to limit the "damage" that a ill-written CGI can do. I
would feel more comfortable hosting my applications with some folks that
understand how to do that as well.
From what you've posted, however, I would suggest doing your homework
before proceeding.
--
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Peter L. Berghold Peter@Berghold.Net
"Those who fail to learn from history are condemned to repeat it."
AIM: redcowdawg Yahoo IM: blue_cowdawg ICQ: 11455958
------------------------------
Date: Sat, 29 Oct 2005 23:03:45 -0400
From: "Peter L. Berghold" <peter@berghold.net>
Subject: Re: why the perl docs suck
Message-Id: <43643815$0$6459$9a6e19ea@unlimited.newshosting.com>
Fred@fred.net wrote:
> I don't fucking *want*
> to think, I wan't a fucking answer right now!
This is a sad self indictment. "I don't want to think... I want an
answer right now." is an idication to me of a lack of desire to learn.
That's sad.
--
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Peter L. Berghold Peter@Berghold.Net
"Those who fail to learn from history are condemned to repeat it."
AIM: redcowdawg Yahoo IM: blue_cowdawg ICQ: 11455958
------------------------------
Date: Sat, 29 Oct 2005 21:16:55 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: windows program return values vs perl return values from a call to system() -- windows post only
Message-Id: <slrndm8b8n.but.tadmc@magna.augustmail.com>
Fred@fred.net <Fred@fred.net> wrote:
> system("$prog_to_B_run");
perldoc -q vars
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V10 Issue 8587
***************************************