[10852] in Perl-Users-Digest
Perl-Users Digest, Issue: 4453 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 18 14:07:23 1998
Date: Fri, 18 Dec 98 11:00:22 -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, 18 Dec 1998 Volume: 8 Number: 4453
Today's topics:
? (question mark) not recognised. (Jason Q.)
Re: ? (question mark) not recognised. (Erik)
An example of good file locking please shaleh@livenet.net
Re: Close and ReOpen File (Tad McClellan)
Re: Close and ReOpen File (Bart Lateur)
Database with locking mechanism? <noemi@dfki.uni-sb.de>
Re: Dynamic PERL Pages in Search Engines? (Greg Ward)
Re: Happy Birthday! <r28629@email.sps.mot.com>
Help .... looking for /etc/group parser <santosh_kutty@compuware.com>
Re: Help .... looking for /etc/group parser <uri@sysarch.com>
How to handle the "require" error <kcchan@csis.hku.hk>
Re: How to handle the "require" error <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Installing C++ compiler after perl on WindowsNT (Jan Dubois)
Re: Installing pm files for Perl Win32 <pep_mico@hp.com>
Re: Installing pm files for Perl Win32 dturley@pobox.com
Re: Intentionally causing a trap/dump/GPF? (Greg Ward)
Re: Interesting Forking Problem (Greg Ward)
Re: log using CGI.pm (Abigail)
Re: numbers in base 36 <ckuskie@cadence.com>
Reverse Sort Hash by Value uncle_remus@my-dejanews.com
Re: Review This For Me? (Note: 166 lines of code) (Greg Ward)
Security in Distributing Scripts. mjswart@my-dejanews.com
Re: Segmentation Fault on 5.00502 (Greg Ward)
Re: STANDARD PERL5_005 for WIN 95/NT (Johannes Poehlmann)
Re: string to float <ckuskie@cadence.com>
Telnet on Win NT server 4.0 <tonylabb@infonline.net>
Unix / Nt Perl Modules ?? <kim@metanoia.demon.co.uk>
Why references get created in an r-value context? <tomek@rentec.com>
Re: Why references get created in an r-value context? (Sean McAfee)
Re: Why references get created in an r-value context? <uri@sysarch.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Dec 1998 17:32:28 GMT
From: pigs_can_fly@mindless.com (Jason Q.)
Subject: ? (question mark) not recognised.
Message-Id: <367c8e50.6525219@news.cyberway.com.sg>
I can't figure what's wrong with my code.
Basically it searches for $RSTRING1, then splice it with $RSTRING2.
It works fine except when $Value[$question1] and/or $Value[$answer1]
has a "?" (question mark) in it, whereby
1. it isn't able to match $array[$found] with $RSTRING
2. $halt then equals 0
3. splice dumps $RSTRING2 to the first line of the $datafile.
How do I get the code to recognise the "?"
Any help would be appreciated.
Thanks
Jason Q.
----------------------------------------------------------------
$RSTRING1 = "$Value[$question1] $Value[$answer1]";
$RSTRING2 = "$Value[$question2] $Value[$answer2]";
open(HANDLE, "$datafile");
@array = <HANDLE>;
close(HANDLE);
$found = 0;
foreach $i (@array)
{
if ($array[$found] =~ $RSTRING1)
{
$halt = $found;
}
$found++;
}
splice (@array, $halt, 1, "$RSTRING2\n");
open(HANDLE, ">$datafile");
print HANDLE @array;
close(HANDLE);
----------------------------------------------------------------
------------------------------
Date: 18 Dec 1998 18:11:23 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: ? (question mark) not recognised.
Message-Id: <75e5sb$efr$1@news.cyberhighway.net>
[Posted and mailed]
In article <367c8e50.6525219@news.cyberway.com.sg>,
pigs_can_fly@mindless.com (Jason Q.) writes:
> if ($array[$found] =~ $RSTRING1)
=~ binds a scalar to a pattern match, substitution, or translation,
and parses the contents of $RSTRING1 as a regular expression.
Of course, '?' is a special character in a regex. To fix,
change the above to
if($array[$found] =~ /\Q$RSTRING1/)
HTH!
--
Erik Nielsen, Cyberhighway Internet Services NOC
print rand rand rand 1, "\n"; # interesting distribution
-- Larry Wall in <199806191536.IAA19013@wall.org>
------------------------------
Date: Fri, 18 Dec 1998 17:00:47 GMT
From: shaleh@livenet.net
Subject: An example of good file locking please
Message-Id: <75e1ns$6c9$1@nnrp1.dejanews.com>
Could someone post a good example of file locking or point me towards one on
the Net somewhere? Preferably using flock but if there is a better way, will
take that instead.
Questions I have include:
how do I detect and exclusive lock?
do flocks go away if the app dies?
Essentially I am in a multi-app or thread situation where the same program
could be writing to the file at once and I am trying to avoid a race while at
the same time another app may be reading from that file (not writing).
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 18 Dec 1998 10:12:51 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Close and ReOpen File
Message-Id: <3uud57.pft.ln@magna.metronet.com>
Bryce Pursley (hbpursle@duke-energy.com) wrote:
: For those of you who responded I wanted to be curtious enough to
: provide the solution I found to the problem. Early in the program I
: had issued the following command . . .
: $/ = "";
: This allowed me to read and process multiple lines of the input file.
: When I closed and then reopened the file I needed to read lines
: separated by carriage returns but I had not changed the $/ setting.
: When I used a separate script the default $/ setting was \n which
: worked great. I have added the new setting . . .
: $/ = "\n";
: just prior to reopening the file and everything works fine.
Or, the more usual way is to just localize your change to $/, then
you don't need to restore it explicitly:
{
local $/ = ''; # paragraph mode
while (defined ($para = <>)) {
# do stuff
}
}
# here perl itself has arranged for $/ to be restored to its
# original value
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 18 Dec 1998 18:39:49 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Close and ReOpen File
Message-Id: <367a9b29.1022813@news.skynet.be>
Tad McClellan wrote:
>{
> local $/ = ''; # paragraph mode
Is that the empty string? You don't need that. undef is just as
acceptable. So "local $/" is all you need. ("Look ma, no warnings!")
> while (defined ($para = <>)) {
> # do stuff
> }
>}
Urm... Won't the WHOLE file be read in one statement?
$theLot = <FILE>;
Of course, if you use <> and there is more than one file, each call will
return the contents of one file. So, in that case, you DO need the while
loop.
Try this:
#! perl -w
{
local $/;
while (<>) {
print ">>> $ARGV\n";
print;
print "<<<";
}
}
and call it with a glob on the command line, like "*.pl". It will then
list all Perl scripts, with a preceding title.
Bart.
------------------------------
Date: Fri, 18 Dec 1998 18:23:44 +0100
From: Annette Preissner <noemi@dfki.uni-sb.de>
Subject: Database with locking mechanism?
Message-Id: <367A8FA0.D7157310@dfki.uni-sb.de>
Hi,
I have a perl script in which I count word frequencies in a document and
store
them in a database file. Each run of the script updates the database
file (the fre-
quency of each encountered word is increased by the number of its
occurences
in the new document ... ).
I first used dbmopen, but then discovered that a locking mechanism is
needed,
since concurrent calls of my script are possible (or rather the rule).
Since no
locking mechanism comes along with dbmopen, I decided to use Berkeley DB
via DB_File instead.
I then noticed that my database file now contains Perl source code - I
found
an explanation for that in the DB_File documentation - Berkeley DB uses
dy-
namic memory without clearing it when allocating ... so that's why you
might
find in your database file anything stored in memory before ...
The documentation says that this is nothing to worry about, but I'm
indexing
thousands of documents, so I wonder if the strange behaviour of Berkeley
DB
might not cause some disk space problems?
If the answer is "yes" - can anybody advise me on what to use instead of
Berke-
ley DB? I work under Solaris ...
Thanks in advance, Annette
------------------------------
Date: 18 Dec 1998 18:38:00 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Dynamic PERL Pages in Search Engines?
Message-Id: <75e7e8$alv$3@news0-alterdial.uu.net>
Stewart Eastham <sme@planetpod.com> wrote:
> We are creating a database driven website using HTML templates, PERL and
>
> mySQL. The content for many pages does not physically live on any
> particular page, and is filled in by a PERL script upon request. What is
>
> the process for ensuring that sites like this get indexed in search
> engines, if at all possible? Additionally, we recently reorganized our
> site's structure and many search engines on the net have the links
> wrong,
> and we'd like to reindex. Is there an easy way to do this, like a meta
> index which reindexes many (or all) other engines? Or is there something
>
> like a script which we may install on our server which can broadcasting
> to
> search engines when our site's content or structure changes?
This question has nothing to do with Perl. You would be much more
likely to find an answer somewhere in the comp.infosystems.www.*
hierarchy.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Fri, 18 Dec 1998 10:56:12 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Happy Birthday!
Message-Id: <367A892C.1B552F@email.sps.mot.com>
I R A Aggie wrote:
>
> In article <75co4t$1gk$1@picasso.op.net>, mjd@plover.com (Mark-Jason
> Dominus) wrote:
>
> + Perl is 11 years old today.
>
> At least I'm using a language younger than I am...
>
> James
I believe you are younger than English language, aren't you? ;-)
-TK
------------------------------
Date: Fri, 18 Dec 1998 11:17:38 -0600
From: Santosh kutty <santosh_kutty@compuware.com>
Subject: Help .... looking for /etc/group parser
Message-Id: <367A8E31.9F134567@compuware.com>
This is a multi-part message in MIME format.
--------------4EEEF4B1965910416FC6649D
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit
Hi,
I am looking for a script that parses the /etc/group file and does all
the standard things like adding a group, deleting a group, adding users
to a group etc .... I am sure that there is one out there ... I just
don't want to re-invent the wheel !!
Does anyone have a similar script ... or know where I can find one ??
I would appreciate any help .... you email me directly at
santosh_kutty@compuware.com
Thank you in advance,
-Santosh
--------------4EEEF4B1965910416FC6649D
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for santosh_kutty@compuware.com
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: santosh_kutty@compuware.com
n: ;santosh_kutty@compuware.com
email;internet: santosh_kutty@compuware.com
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
end: vcard
--------------4EEEF4B1965910416FC6649D--
------------------------------
Date: 18 Dec 1998 13:19:09 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Help .... looking for /etc/group parser
Message-Id: <x7ww3pmhya.fsf@sysarch.com>
>>>>> "Sk" == Santosh kutty <santosh_kutty@compuware.com> writes:
Sk> I am looking for a script that parses the /etc/group file and does
Sk> all the standard things like adding a group, deleting a group,
Sk> adding users to a group etc .... I am sure that there is one out
Sk> there ... I just don't want to re-invent the wheel !!
use a better subject. (someone tell hime the url for the subject doc).
your subject asks for a parser which perl has builtin (getgr* funcs).
then you ask for a module to update /etc/group.
Sk> Does anyone have a similar script ... or know where I can find one
search cpan or the net with a search engine.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sat, 19 Dec 1998 00:27:48 +0800
From: Rollo Chan Ka Chun <kcchan@csis.hku.hk>
Subject: How to handle the "require" error
Message-Id: <Pine.GSO.4.03.9812190025510.98-100000@genius>
Dear All,
I would like to ask...the "require" statement will cause a fatal
error when the required file not found...which mean cannot execute the
PERL script anymore.....is that any method to handle this error and
contine to execute the script???...thanks for your help...=)
Regards,
Rollo
______ ______ __ __ ______
/_____/| /_____/| /_/| /_/| /_____/| /\ /\
| _ || | _ || | || | || | _ || /\ \ /\ \
| |_| || | | | || | || | || | | | || / \ \ / \ \
| _|/ | | | || | ||___ | ||___ | | | || /_/\_\/_ /_/\_\/
| |\ \ \ | |_| || | |___/| | |___/| | |_| || /___/|
|_|/\_\/ |_____|/ |_____|/ |_____|/ |_____|/ |___|/
<Pretend you are happy when you are blue,
it isn't very hard to do......>
------------------------------
Date: 18 Dec 1998 17:56:58 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: How to handle the "require" error
Message-Id: <83lnk5fkx1.fsf@vcpc.univie.ac.at>
Re: How to handle the "require" error, Rollo
<kcchan@csis.hku.hk> said:
Rollo> Dear All, I would like to ask...the "require"
Rollo> statement will cause a fatal error when the
Rollo> required file not found...which mean cannot
Rollo> execute the PERL script anymore.....is that
Rollo> any method to handle this error and contine
Rollo> to execute the script???...thanks for your
Rollo> help...=)
Yes, enclose the require in an `eval' and check $@
afterwards. Outline:
eval {
require 'missing.pl';
};
if ($@) {
# handle error
}
else {
# ok, require worked
}
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Fri, 18 Dec 1998 17:56:48 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: Installing C++ compiler after perl on WindowsNT
Message-Id: <3682806a.110295436@news3.ibm.net>
[mailed & posted]
mwas@my-dejanews.com wrote:
>I have installed Visual C++ 4.0 on WinNT (yes, that's a rather old VC++ Win32
>version but it's all I've got) AFTER having installed the pre-compiled
>PERL5.005_02 from ActiveState.
>
>I'll need VC++ to compile modules such as Time-Hires because ActiveState
>doesn't provide these binary form (they DO provide binaries for the more
>common CPAN modules).
>
>I've checked the settings in Config.pm that Randy mentioned and they seem to
>be allright. However when running nmake I get the following Warning: Command
>line warning D4002 : ignoring unknown option '-TP'
>
>Then CL.EXE gives me a long list of errors that all originate in *.h files
>example: D:\Perl\lib\CORE\perl.h(102) : error C2282: 'class' is followed by
>'CPerlObj' (m issing ','?)
>
>Anyone know what the -TP option means in the newer releaes of VC++ ?? Could
>this be the reason that compilation fails? Anyone out there who has
>successfully compiled modules using VC++ 4.0 ?
Michael,
I think you have a serious problem: Perl 5.005 will not compile with the
PERL_OBJECT option under VC++ 4.x. PERL_OBJECT is the technology
ActiveState uses to encapsulate a Perl interpreter in a C++ object. In
this mode everything must be compiled in C++, which is what -TP is
telling: even if this file is called xxx.c and not xxx.cpp it should still
be treated as C++.
Unfortunately the CPerlObj uses circular forward references that VC++ 4.x
doesn't understand. I once tried for some time to solve this using forward
declarations etc, but VC++ 4.2b just wouldn't grok it. Perl 5.005 with
PERL_OBJECT currently requires VC++ 5.0 or later. It compiles with EGCS
but for some strange reasons doesn't work.
So there are 2 solutions: Either upgrade to VC++ 5.0 or VC++ 98. Or
compile Perl yourself without PERL_OBJECT support. You don't need
PERL_OBJECT if you are not using any of the ActiveState stuff, like
PerlScript, PerlCOM, PerlCtrl or PerlIS and whatever else they might have.
Of course you cannot use their PPM repository but must build all
extensions yourself because PERL_OBJECT and non-PERL_OBJECT extensions are
not binary compatible. But that shouldn't be such a big problem, because
you do have a C compiler. (You'll not be able to compile Win32::OLE
though, you'll need VC++ 4.2b at least for that).
-Jan
------------------------------
Date: Fri, 18 Dec 1998 18:39:29 +0100
From: Pep Mico <pep_mico@hp.com>
To: Bob Stickel <bstickel@dot.state.oh.us>
Subject: Re: Installing pm files for Perl Win32
Message-Id: <367A9351.FCEAF5A1@hp.com>
Just run ppm.pl script.
I'll recommend you read the ppmproxy.htm that comes with documentation if you
use a Proxy firewall to have Internet connection. If you use it just type
set HTTP_PROXY=http://your-proxy:8088
then run ppm.pl and you should select the command to install modules, like
"Install win32::filesecurity" that will isntall the FileSecurity module in your
computer.
I hope that this orientation helps you.
Regards
pep_mico@hp.com
Bob Stickel wrote:
> I just got started with ActiveState's version 5.005_02 under 95 and NT with
> no particular problems. Now I would like to install some modules but can't
> figure out exactly what I need to do. I understand the make commands from
> previous Linux experience but I don't have a C compiler installed on my
> Win32 platforms. Do I need to get the GNU DOS version and compile the
> modules before they can be installed or do I need to have a Win32 C
> compiler? I have Borland and Msoft available for installation but really
> don't want to install them unless absolutely necesssary.
>
> Thanks
>
> Bob
------------------------------
Date: Fri, 18 Dec 1998 18:34:52 GMT
From: dturley@pobox.com
Subject: Re: Installing pm files for Perl Win32
Message-Id: <75e78c$bbd$1@nnrp1.dejanews.com>
In article <367a56d4.0@socnm002.dot.state.oh.us>,
"Bob Stickel" <bstickel@dot.state.oh.us> wrote:
> I just got started with ActiveState's version 5.005_02 under 95 and NT with
> no particular problems. Now I would like to install some modules but can't
> figure out exactly what I need to do.
What happened when you followed the instructions for installing modules
using PPM that come with ActivePerl?
____________________________________
David Turley
dturley@pobox.com
http://www.binary.net/dturley/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 18 Dec 1998 18:41:32 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Intentionally causing a trap/dump/GPF?
Message-Id: <75e7ks$alv$4@news0-alterdial.uu.net>
chess@watson.ibm.com <chess@watson.ibm.com> wrote:
> Is there some portable way in Perl to cause the current OS's
> version of a nasty crash? (GPF, trap, coredump, whatever?)
abort() is the C/POSIX way of doing this, and unsurprisingly Perl's
POSIX module supports it:
% perl -MPOSIX -e 'POSIX::abort'
Abort (core dumped)
(Hey, Perl dumped core! I must have found a bug! ;-)
Should work, for varying definitions of "portable"...
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: 18 Dec 1998 18:54:40 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Interesting Forking Problem
Message-Id: <75e8dg$alv$5@news0-alterdial.uu.net>
Joseph M Carlton <carltjm@mail.auburn.edu> wrote:
> I'm having an interesting problem and I could really use some advice. I
> am working on a cgi perl script that executes another perl script
> called update_user_profile.perl (this one takes a while to run) via a
> fork. This second perl script executes an expect sript call up_push.sh
> via backquote (this program ftp's a file).
>
> I can get everything to work properly, except Netscape hangs and waits
> for all of the script's children to finish executing. To fix this, I
> closed STDIN, STDOUT, and STDERR. This fixes the Netscape hanging
> problem, and the update_user_profile script is still executed, but the
> up_push.sh program will not run. (it shows up in ps -ef, but it is just
> dead). The weird thing is that everything still works fine if I run the
> cgi script from the command line.
Hmmm... mentioning "expect script" and "closed STDIN, STDOUT, and
STDERR" set off a little bell in my head. I've never used expect, but I
imagine it needs stdin and stdout to communicate with the interactive
program that it's attempting to control! That might be part of the
problem.
I would advise a bit of a rethink. With the incredible wealth of
network-related Perl modules now available, I strongly doubt that you
need expect. If your up_push.sh script is just used for ftp (I know you
didn't say that, but just suppose...), then you can easily ditch it and
use the Net::FTP module straight from Perl. *Much* nicer way of doing
things. Takes about 20 minutes to get and up running with Net::FTP (or
any of Graham Barr's Net::* modules -- all have clean, clear OO
interfaces and just enough documentation to get you up to speed).
> Here's the code from the cgi program where I do the fork:
> sub spawn {
> my $coderef = shift;
> my $pid;
>
> if (!defined($pid = fork)) {
> return;
> } elsif ($pid) {
> return; # I'm the parent
> }
> # else I'm the child -- go spawn
>
> close(STDIN);
> close(STDOUT);
> close(STDERR);
> exit &$coderef();
> }
>
> Here's where I call subroutine spawn in the cgi program:
> spawn sub {
> `/home/Netscape/cgi-bin/user_profile/update_user_profile.perl`;
> };
Ummm... I detect a bit of weirdness in your code. The anonymous
subroutine that is passed to 'spawn' returns the stdout of
'update_user_profile.perl' as a single string. Unless you're doing
something really weird and subtle, I think you're misunderstanding the
backquote operator.
I would rewrite your spawn as:
sub spawn {
my $cmd = shift;
my $pid;
if (!defined($pid = fork)) {
return;
} elsif ($pid) {
return; # I'm the parent
}
# else I'm the child -- go spawn
close(STDIN);
close(STDOUT);
close(STDERR);
exec @$cmd;
die "exec failed!"; # message will be lost, but at least
# failure status will be registered
}
and call it like
spawn (['/home/Netscape/cgi-bin/user_profile/update_user_profile.perl']);
Note the use of the list form of exec: highly recommended in any
production code, especially CGI or setuid scripts.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: 18 Dec 1998 18:27:54 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: log using CGI.pm
Message-Id: <75e6ra$p68$1@client3.news.psi.net>
6})lRD (youzi.bbs@MSIA.pine.ncu.edu.tw) wrote on MCMXXXV September
MCMXCIII in <URL:news:3S8AdP$8Oy@MSIA.pine.ncu.edu.tw>:
++
++ I used remote_host() to read where the user came from,
++ but when remote user use proxy server to catch data,
++ I can only know the proxy server's IP, but not the real one,
And? That's all you need. Besides, the user doesn't even need to have
an IP address.
++ what shall I do?
That depends. What do you need the users IP number for? Low level
protocols will take care of sending the data to the appropriate
address.
++ Thanks for answering.
Of course, none of this has anything to do with Perl.
Abigail
------------------------------
Date: Fri, 18 Dec 1998 09:35:40 -0800
From: Colin Kuskie <ckuskie@cadence.com>
To: deja@kiama.com
Subject: Re: numbers in base 36
Message-Id: <Pine.GSO.3.96.981218092552.25649B-100000@pdxue150.cadence.com>
[And Emailed...]
On Fri, 18 Dec 1998 deja@kiama.com wrote:
> Is there a way for perl to read numbers in bases other 8,10, and 16?
Yes, they're called subroutines :)
> There is a function in Java to format an integer in any base, I would
> like to create a base 36 number in java and pass it to a perl script.
> Can perl convert it back to decimal?
my $c = 0;
my %lh = map { $_ => $c++ } 0..9,'a'..'z';
sub b36todec1 {
my $b36num = $_[0];
my $decnum = 0;
$b36num =~ tr/A-Z/a-z/;
my $method = 1;
if ($method == 1) {
##Use a regular expression
s/(.)/$decnum += $lh($1)/eg;
}
elsif ($method == 2) {
##Use split and iterate over the characters
foreach (split //, $b36num) {
$decnum += $lh{$_};
}
}
elsif ($method == 3) {
##Use for and substr
#for ($_ = 0; $_ <= length $b36num; $_++) {
for (0..length $b36num) {
$decnum += $lh{substr($b36num,$_,1)};
}
}
else {
##Roll you own method here.
}
return $decnum;
}
Now, a real programmer (I'm not one) would benchmark all those with
number of varying lengths and find out which one is the most efficient.
Also, I haven't tested this code extensively, so do be careful.
Colin
------------------------------
Date: Fri, 18 Dec 1998 15:47:19 GMT
From: uncle_remus@my-dejanews.com
Subject: Reverse Sort Hash by Value
Message-Id: <75dte6$28f$1@nnrp1.dejanews.com>
I am trying to reverse sort a (perl) hash by value and assign these sorts a
ranking,
i.e. 1 for the lowest value, etc. The ultimate goal is something like $Hash
{$Key}=$Value ===> $Hash{$Key.Rank}=1, etc. where the values are not
necessarilly unique (so that, e.g., two values could receive the same rank).
Any suggestions??!!
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 18 Dec 1998 18:26:36 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Review This For Me? (Note: 166 lines of code)
Message-Id: <75e6os$alv$1@news0-alterdial.uu.net>
Jim Seymour <jseymour@jimsun.LinxNet.com> wrote:
> I've been learning/coding Perl for a few months now, and I *think*
> I'm ready to submit my progress in learning the language to the
> slings and arrows of those who've been doing it a lot longer :-).
[big comment deleted]
Good start: documentation! Always important. Might be useful to put
usage info like this as a POD, though.
> use strict;
> use Getopt::Std;
>
> use vars qw(
> $usageMsg
> $size $fname $direction $userType $userID $agent
> $opt_q $opt_d
> $dateStr
> @flds
> %userInCnt %userInSize %fileInCnt %anonInCnt %anonInSize
> %anonFileInCnt %userOutCnt %userOutSize %fileOutCnt %anonOutCnt
> %anonOutSize %anonFileOutCnt
> );
Saying 'use strict' and then declaring a whole bunch of global variables
is better than not using strict at all, but it's kind of silly. After
all, the whole point of 'use strict' is to tell Perl that you're going
to be a good boy today and not use any global variables. 'use vars' lets
you fudge a bit and use *one* or *two* global variables. The only
time you should 'use vars' in production code, IMHO, is when you absolutely
must have a package-level global variable, such as @ISA or @EXPORTS, or
maybe a global that outsiders can set ("$MyPackage::Customize = ...").
You should just ditch your 'use vars' and declare all these variables as
lexically scoped using 'my'. Makes your code much easier to maintain:
how many times did you have to go back and edit the 'use vars' to
add yet another new variable?
> $opt_q = 0; # for "simpler" tests later in case not set
> getopts('qd:') ||
> die "$usageMsg\n";
getopts lets you be strict and avoid the "set a variable named after an
option" hack. I would do it like this:
my %opt;
getopts ('qd:', \%opt) ||
die "$usageMsg\n";
and then refer to $opt{'q'} where you now refer to $opt_q, etc.
(Careful though: I think you have to test "exists $opt{'q'}" where
you now test "defined $opt_q", which is a bit counterintuitive. RTFM
on Getopt::Std for the full scoop, though.)
The rest of your code looks fine. I don't see anything that will have
to change if you fix to use 'my' for all your now-global variables, but
I bet you'll find some spots where a subroutine is using a global
variable that *should* be passed in as a parameter. That's the
sort of bug that 'use strict' helps you find, and 'use vars' lets
you get away with -- which is why 'use vars' should be used sparingly.
Oh, good move on passing hash refs to your print_file_by_cnt_vals sub.
That's the way to go...
> How am I doing?
A lot better than a lot of newbies who post here! Get rid of your
global variables and your karma will shoot up...
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Fri, 18 Dec 1998 18:30:32 GMT
From: mjswart@my-dejanews.com
Subject: Security in Distributing Scripts.
Message-Id: <75e709$b2m$1@nnrp1.dejanews.com>
When I write a c++ program, compile it, and distribute it, I am
confident that noone can look at my source code since it is difficult
to decompile an optimized executable.
In a Perl program, since the scripts are interpreted, they must be
distributed as is.
My question:
Are there methods to preserve the scripts?
Some sort of compiler? (not too keen on this one)
Any encryption methods which would allow Perl.exe to have the script
but noone else?
Assuming the user does not know the method of encoding is obviously
not an option.
Has anyone else come across this problem? and if so how did you deal
with it?
Mike Swart
reply to this post, or to Michael.Swart at switchview.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 18 Dec 1998 18:36:28 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Segmentation Fault on 5.00502
Message-Id: <75e7bc$alv$2@news0-alterdial.uu.net>
Ken Collier <kcollier@soli.inav.net> wrote:
> I am a relative beginner in PERL and am not sure where to turn. My
> program runs continuously servicing Web requests ( when working ).
>
> I am getting consistent segmentation faults in PERL 5.00502 on a RS6000
> box.
First question: are any extension (XSUB) modules used by your program?
If so, it might be their fault rather than Perl's. It also makes things
harder to figure out. ;-( (Unless those XSUB modules are statically
linked into Perl -- the blame is apportioned the same way, but it's
easier to debug.)
> The program dies after it has been running a long time, anywhere from
> four hours to four days. I don't know if the time difference is related
> to load. And I don't know what code is executing when it dies.
>
> Excuse my ignorance, but is there a way to find out where it is dying
> after such a long time? And any other clues on how to proceed would be
> appreciated. Thank you.
Considering the long running time, using Perl's own debugging facilities
is probably not an option; they're quite verbose and slow things down a
lot. You might have to wait four months instead of four days, and your
disk would probably fill up with debugging messages.
However, you can always go a level deeper: look at the C. It really
really helps if your Perl was compiled with -g and not stripped on
installation. Do 'perl -V' to find out. You might try recompiling Perl
with debugging info (compile with -g is more important in this case than
enabling Perl's internal debugging -- the -DDEBUGGING thing -- because of
the space and time effects of -DDEBUGGING).
Also, make sure your core files are not truncated; many people/sites
have resource limits set to truncate core files, but in this case you'll
want the whole thing. If the core file is big (several megabytes) and
doesn't have an obviously rounded-looking size, it's probably complete.
If it is truncated, try the 'ulimit' or 'limit' command (depending on
your shell) to remove the restrictions, and rerun Perl until it dumps
core.
Having done all that, you should have a complete core file and a Perl
binary with enough information to be useful. Now you just need a C
debugger; gdb is good and widely available, so try it first. Run the
following shell command:
% gdb /usr/local/bin/perl --core=/path/to/core
for appropriate values of /usr/local/bin/perl and /path/to/core. Then
type 'where': gdb should tell you where Perl dumped core. That should
be enough information to submit with the 'perlbug' script. (It would
also be great if you could shrink your script down to something
reasonable, but that might be hard given the "4 hours .. 4 days" running
time.)
If you don't have gdb, you might need to use dbx. I'm not sufficiently
familar with dbx to help; ask a local guru, or RTFM, or something.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: 16 Dec 1998 00:00:00 +0000
From: j.poehlmann@link-n.cl.sub.de (Johannes Poehlmann)
Subject: Re: STANDARD PERL5_005 for WIN 95/NT
Message-Id: <76xBtNCJUkB@link-n-j.poehlmann.link-n.cl.sub.de>
dragons (Matthew Bafford) wrote
as answer to my posting:
> => _Where to find the *STANDARD* windows 95/NT port of perl (binary) ?_
> The most *RECENT* port is the *STANDARD* port.
> And, since AS's release is 5.005_02, and GS's is only 5.004_02 (IIRC,
> over a years span between the two), I'd say AS's is much more recent than
> GS's.
Indeed Gurasamys perl5_004_02-bindist04-bc.zip archive was the last
PRECOMPILED distribution binary of the standard distribution
i found.
> Since it's more recent, that makes it the *STANDARD* port.
No. the perl gurus integrated the windows support in
the standard source distribution. Gurusamy obviously
takes part in this developement.
So you must compile perl. But do'nt worry. Even I was able
to compile perl on several UNIXes.
See some snippets from the FILE: README.win32.
This file is part of the perl source distribution
BEGIN QUOTATION:
####################
=head1 NAME
perlwin32 - Perl under Win32
....
Currently, this port is capable of using one of the
following compilers:
Borland C++ version 5.02 or later
Microsoft Visual C++ version 4.2 or later
Mingw32 with EGCS version 1.0.2
Mingw32 with GCC version 2.8.1
....
Beginning with version 5.005, there is experimental support for building
a perl interpreter that is capable of native threading.
=head1 AUTHORS
Gary Ng E<lt>71564.1743@CompuServe.COME<gt>
Gurusamy Sarathy E<lt>gsar@umich.eduE<gt>
Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>
This document is maintained by Gurusamy Sarathy.
###################
END QUOTATION
--
Johannes Pvhlmann * Memelstr 4 * 91052 Erlangen * Tel.: (0)9131 16435
pgp - Schl|ssel: Nachricht mit Betreff ## an mich
pgp key: Send message to me with subject ##
------------------------------
Date: Fri, 18 Dec 1998 09:17:42 -0800
From: Colin Kuskie <ckuskie@cadence.com>
To: Steven Ford <steven.m.ford@vanderbilt.edu>
Subject: Re: string to float
Message-Id: <Pine.GSO.3.96.981218091136.25649A-100000@pdxue150.cadence.com>
[And emailed to Mr. Ford]
On Thu, 17 Dec 1998, Steven Ford wrote:
> $line = "*99880060288399999999990100000309200104315876"
>
> $amount = substr ($line,35,11); # $line = "0104315876"
> $amount =~ s/^0+//; # Strip leading zeros $line = "104315876"
$amount += 0; #Force evaluation as a number to remove leading zeroes
> I need to display $line as: $1043158.76
>
> I used printf with %8.2f but it did not place the decimal for me,
> instead it did 104315876.00
What you asked for was the number with two decimal places. Since
your number is an integer int($amount) == $amount, you got exactly
what you asked for. You need to introduce a decimal point:
$amount /= 100;
or
substr($amount,-2,0) = '.';
Now try that sprintf.
HTH,
Colin
------------------------------
Date: Fri, 18 Dec 1998 11:58:26 -0500
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Telnet on Win NT server 4.0
Message-Id: <367A89B2.8C7244AE@infonline.net>
I am currently trying to port a perl program from Unix to Win Nt 4.0. I
have checked the directories to make sure the telnet module exists, and
it does. We are using the most current version of ActiveState's Perl,
which I believe is 5.005. I am including a snippet of code and the error
I am getting. I thought I had seen this exact message posted to this
group before, but I haven't been able to find it again. I have checked
the directory structure several times in order to make sure my syntax is
correct. This code works fine on Unix (Solaris 2.4). The only difference
is in Unix, the line reads, "use Net::Telnet();". Anyhow, here it is:
use URI::URL::telnet();
FIN: while ($annex = <DATA>) {
@ports = ();
@lines = ();
$remote = new URI::URL::telnet(Timeout => 10, Prompt => '/ $/', Errmode
=> 'return');
print "Opening Connection...\n";
$status = $remote->open($annex);
if ( ! $status ) {
chop $annex;
print "Annex $annex is down!\n\n";
next FIN;
}
$remote->cmd('cli');
# there is more code between here and __END__ which is not
# needed to explain the problem any further.
__END__
IP 1
IP 2
IP 3
Error:
Can't locate auto/URI/URL/telnet/open.al in @INC (@INC contains:
C:\Perl\5.00502\lib/MSWin32-x86-object C:\Perl\5.00502\lib
C:\Perl\site\5.00502\lib/MSWin32-x86-object C:\Perl\site\5.00502\lib
C:\Perl\site\lib .) at C:\InetPub\scripts\annex.pl line 27
--
****************************************
* Tony Labbiento *
* Infinity Online, Inc. *
****************************************
------------------------------
Date: Fri, 18 Dec 1998 16:23:01 -0800
From: "Kim Squires" <kim@metanoia.demon.co.uk>
Subject: Unix / Nt Perl Modules ??
Message-Id: <913998326.15510.0.nnrp-05.c30b0522@news.demon.co.uk>
I am running a pl script that uses the Date::Manip routines ... from an NT
server.
I get an error message posted back :
ERROR: Date::Manip unable to determine TimeZone. Date::Manip::Date_TimeZone
called at C:\perl\lib\site/Date/Manip.pm line 2332
What concerns me here is the change in the slashes from ' \ ' to ' / ' in
the middle of the path statement.
Which to me suggests I am running a unix version of the specified module, as
opposed to the Nt version ?
And the string passed in being Nt is being added to a unix string ???
Or am I abit misguided here ...
Any possiblities, thoughts, answers... would be greatly appreciated ... :)
Kim
------------------------------
Date: Fri, 18 Dec 1998 11:24:49 -0500
From: Tomasz Kozlowski <tomek@rentec.com>
Subject: Why references get created in an r-value context?
Message-Id: <367A81D1.2FD271B5@rentec.com>
I ran into problems with Perl while using the following kind of code
$val = $data->{$date}->{$attr} || '';
The variable $val gets either the value from the hash
or gets initialized to the empty string. Everything works as expected.
If the hash doesn't contain anything for the specified values, however,
some references magically spring into existence and the hash gets updated.
This isn't what I expected. For example, the following statements
$data = {};
$date = '19981215';
$attr = 'name';
$val = $data->{$date}->{$attr} || '';
will cause the hash reference to become
$data->{'19981215'} = {}
To me this is a bug in Perl either in the implementation or specification.
I consulted 'Programming Perl', 2nd Ed by Wall, Christiansen and Schwartz
and on page 250 the authors say:
"This is one of the cases mentioned earlier in which references spring
into existence when used in an lvalue context ...
Nothing would spring into existence if you were just trying to print out
the value. You'd just get the undefined value out of it."
I talked to quite a few people around and nobody said that's a desirable
behavior but people tended to defend Perl along the lines "It's easy
to imagine why it does that". Well, yes, it's easy to imagine what's
happening but that doesn't mean Perl should do that. It seems to me that
using a hash reference in a an r-value context should not update the hash.
The keys construct behaves similarly. I have many loops for iterating
over the contents of a hash that look like
foreach $date (keys %$data)
{
foreach $attr (keys %{$data->{$date}})
{
$val = $data->{$date}->{$attr};
...
}
}
This snippet of code doesn't give me any surprises. But if I change it to
foreach $date (@dates)
{
foreach $attr (keys %{$data->{$date}})
{
$val = $data->{$date}->{$attr};
...
}
}
and the hash initially doesn't contain anything for some date, well,
too bad, Perl will create a spot for it and assign to it a reference to an
empty hash. To give a shorter example:
$data = {};
@attrs = keys %{$data->{'19981215'}};
$data is now
$data->{'19981215'} = {}
Again, things get changed when a reference is used in an r-value context.
To make thing worse the defined function has the same 'feature':
$data = {};
if( defined( $data->{'19981215'}->{'attr'} ) )
{ print( "defined\n" ); }
else
{ print( "undefined\n" ); }
'undefined' gets printed and $data is now
$data->{'19981215'} = {}
It's again easy to imagine why Perl does that but I see no explanation
for this behavior. It's a gross bug.
I'm using Perl 5.003. I also checked how things behaved under Perl 5.00502
and saw no difference. And that's, I believe, the latest version of Perl.
Does anyone know of any way of circumventing this problem?
Tomek
------------------------------
Date: Fri, 18 Dec 1998 18:02:13 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Why references get created in an r-value context?
Message-Id: <FMwe2.2130$4w2.8599371@news.itd.umich.edu>
In article <367A81D1.2FD271B5@rentec.com>,
Tomasz Kozlowski <tomek@rentec.com> wrote:
>I ran into problems with Perl while using the following kind of code
>
> $val = $data->{$date}->{$attr} || '';
[snip; basically a complaint about autovivification]
You realize that the alternative to Perl automatically updating the hash is
a run-time error? If %$data has no entry for the key $date, then
$data->{$date} is undefined, and $data->{$date}->{$attr} really OUGHT to
throw a "Can't use an undefined value as a HASH reference" error.
Getting around this unwanted behavior is fairly simple:
$val = $data->{$date} && $data->{$date}->{$attr} || '';
> To me this is a bug in Perl either in the implementation or specification.
Specifications don't have bugs.
> foreach $date (@dates)
> {
next unless $data->{$date}; # short, sweet, fixes problem
> foreach $attr (keys %{$data->{$date}})
> {
> $val = $data->{$date}->{$attr};
> ...
> }
> }
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: 18 Dec 1998 13:24:00 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why references get created in an r-value context?
Message-Id: <x7u2ytmhq7.fsf@sysarch.com>
>>>>> "SM" == Sean McAfee <mcafee@waits.facilities.med.umich.edu> writes:
SM> In article <367A81D1.2FD271B5@rentec.com>,
SM> Tomasz Kozlowski <tomek@rentec.com> wrote:
SM> [snip; basically a complaint about autovivification]
SM> $val = $data->{$date} && $data->{$date}->{$attr} || '';
>> foreach $date (@dates)
>> {
SM> next unless $data->{$date}; # short, sweet, fixes problem
you might want to use exists also since the poster never said what kind
of data was in his hashes.
there was a thread in p5p about whether exists should autovivify. i feel
it should not and it should bomb out with a false value whenever a level
of a multilevel hash has no entry. using the straight hash expression
should autovivify. i am not sure if the status of exists and
autovivication in the latest mods to perl.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
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 4453
**************************************