[15832] in Perl-Users-Digest
Perl-Users Digest, Issue: 3245 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 3 21:05:39 2000
Date: Sat, 3 Jun 2000 18:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <960080709-v9-i3245@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 3 Jun 2000 Volume: 9 Number: 3245
Today's topics:
floating point algorithm bug in perl 5.6.0? <vvacme@worldonline.nl>
Re: floating point algorithm bug in perl 5.6.0? (Peter J. Acklam)
Re: floating point algorithm bug in perl 5.6.0? <vvacme@worldonline.nl>
Re: floating point algorithm bug in perl 5.6.0? (Eric Bohlman)
How do you pass a hash reference in Perl 4? <sfighter@cs.utexas.edu>
Re: How do you pass a hash reference in Perl 4? <vvacme@worldonline.nl>
Re: How do you pass a hash reference in Perl 4? (Eric Bohlman)
Re: How to escape "/"? <gnari@simnet.is>
Re: Limits on $ENV{} hash ? <phill@modulus.com.au>
Re: Newbie in need of help... <makarand_kulkarni@My-Deja.com>
Re: Newbie in need of help... <phill@modulus.com.au>
Re: Newbie in need of help... <vvacme@worldonline.nl>
Re: Not shifting what I want from an array <tina@streetmail.com>
Re: Predicted generation of ID numbers <phill@modulus.com.au>
Problem using command line arguments <wellhaven@worldnet.att.net>
Re: Problem using command line arguments <vvacme@worldonline.nl>
Re: Problems with MakeMaker om Win32 (ActiveState) <phill@modulus.com.au>
Re: using 'exists' in a program to test for keys in a h <rgw303@mailandnews.com>
Re: Viewing HTTP Requests <flavell@mail.cern.ch>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 04 Jun 2000 01:41:55 +0200
From: Vincent Voois <vvacme@worldonline.nl>
Subject: floating point algorithm bug in perl 5.6.0?
Message-Id: <393997C3.D3226EE3@worldonline.nl>
I noticed a strange behaviour in Perl 5.6.0 build 613
Trying the simple piece of code below i get an output that does not really compute in my mind:
$number = 4.02;
$front = int($number);
$behind = ($number - $front);
print "full $number\n";
print "major $front\n";
print "minor $behind\n";
The minor slice '$behind' supposed to have value of 0.02 but strangely, it returns something near
0.0199999999996 (I may lacked a couple of '9'ers too less or too many).
I know that working with the int function is not advised, could it be that the fpu code engine is getting
confused when it has to subtract an integer value from a floating point unit?
I really miss a solid rounding function in Perl and yes i know that (s)printf has methods to DISPLAY rounded
numbers but you can't put them in variables or process them. The ceil() and floor() functions won't help me
out either since the server i run my scripts on does not have the perl.pm module around neither am i capable
of getting this thing going there myself (when adding it in my own cgi-bin directory) so anything i need to
call with 'use' is being interpreted as an error.
I really need a solid nearing function that rounds up to the nearest number which is not too hard to make but
i can't make this one if the float engine is not reliable.
As i want to make notice that this is for financial purposes which do need a quite precise output and
processing so i guess this bug propbably did not went unnoticed.
Does anyone else get the same result in his/her version of Perl?
Vv.
------------------------------
Date: 04 Jun 2000 02:09:28 +0200
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: floating point algorithm bug in perl 5.6.0?
Message-Id: <cxchfbajohz.fsf@seksognitti.uio.no>
Vincent Voois <vvacme@worldonline.nl> writes:
> I noticed a strange behaviour in Perl 5.6.0 build 613
> Trying the simple piece of code below i get an output that does not
> really compute in my mind:
>
> $number = 4.02;
> $front = int($number);
> $behind = ($number - $front);
> print "full $number\n";
> print "major $front\n";
> print "minor $behind\n";
>
> The minor slice '$behind' supposed to have value of 0.02 but
> strangely, it returns something near 0.0199999999996 (I may lacked a
> couple of '9'ers too less or too many).
Doing maths with floating point arithmetic is not the same as doing
maths in theory. The number 0.02 can't be represented exact with (the
most common types of) floating point arithmetic.
> I know that working with the int function is not advised
I find that hard to believe. The int() function is very useful. You
just have to know when and how to use it.
> could it be that the fpu code engine is getting confused when it has
> to subtract an integer value from a floating point unit?
I believe Perl stores both these numbers as floating point numbers.
> I really miss a solid rounding function in Perl
Here is one you could use. It is faster than a solution based on
sprintf() according to my benchmarking.
sub round ($) {
return int $_[0] + ( $_[0] > 0 ? 0.5 : -0.5 );
}
> and yes i know that (s)printf has methods to DISPLAY rounded numbers
> but you can't put them in variables or process them.
Yes you can. The printf() function is for displaying numbers, the
sprintf() function is for stuffing numbers into variables, presumably
for further processing.
> The ceil() and floor() functions won't help me out either since the
> server i run my scripts on does not have the perl.pm module around
The "perl.pm" module? Never heard of it. Or do you mean the POSIX
module?
> neither am i capable of getting this thing going there myself (when
> adding it in my own cgi-bin directory) so anything i need to call with
> 'use' is being interpreted as an error. I really need a solid nearing
> function that rounds up to the nearest number
*Up* to the nearest number? That would be a ceil() function, I guess:
sub ceil {
my $x = shift;
my $ix = int $x;
return $x <= 0 || $x == $ix ? $ix : $ix + 1;
}
> which is not too hard to make but i can't make this one if the float
> engine is not reliable.
The floating point engine is reliable, you just have to be aware of its
limitations.
> As i want to make notice that this is for financial purposes which do
> need a quite precise output and processing so i guess this bug
> propbably did not went unnoticed.
It's not a bug.
> Does anyone else get the same result in his/her version of Perl?
Yup.
Peter
--
$\="\n";$_='The quick brown fox jumps over the lazy dog';print +(split
//)[20,5,24,31,3,36,14,12,31,1,2,11,9,23,33,29,35,15,32,36,7,8,28,29];
------------------------------
Date: Sun, 04 Jun 2000 02:42:44 +0200
From: Vincent Voois <vvacme@worldonline.nl>
Subject: Re: floating point algorithm bug in perl 5.6.0?
Message-Id: <3939A604.12557FA6@worldonline.nl>
"Peter J. Acklam" wrote:
>
> Vincent Voois <vvacme@worldonline.nl> writes:
>
> > I noticed a strange behaviour in Perl 5.6.0 build 613
> > Trying the simple piece of code below i get an output that does not
> > really compute in my mind:
> >
> > $number = 4.02;
> > $front = int($number);
> > $behind = ($number - $front);
> > print "full $number\n";
> > print "major $front\n";
> > print "minor $behind\n";
> > The minor slice '$behind' supposed to have value of 0.02 but
> > strangely, it returns something near 0.0199999999996 (I may lacked a
> > couple of '9'ers too less or too many).
> Doing maths with floating point arithmetic is not the same as doing
> maths in theory. The number 0.02 can't be represented exact with (the
> most common types of) floating point arithmetic.
I noticed, but as a bridge engineer i would not place my bets on such fpu arithmics or you want to have my
constructions end up on your head one day or fall down with it.
It reminds me of the P75 FPU bug that acted similar back in 1994 and we were not happy with it either.
Though, not that i'm going to desing a bridge-construction in Perl :)
> > I know that working with the int function is not advised
>
> I find that hard to believe. The int() function is very useful. You
> just have to know when and how to use it.
Sorry, it was said that using the int function for rounding procedures was not advised.
> > could it be that the fpu code engine is getting confused when it has
> > to subtract an integer value from a floating point unit?
> I believe Perl stores both these numbers as floating point numbers.
Okay, so if the arithmic function is not capable of translating a two decimals number correctly when
subtracting a another float from it i can understand what is going wrong.
> > I really miss a solid rounding function in Perl
> Here is one you could use. It is faster than a solution based on
> sprintf() according to my benchmarking.
A reason why i quit programming in C++.
The load of work you needed to do with it to accomplish a few things.
> sub round ($) {
> return int $_[0] + ( $_[0] > 0 ? 0.5 : -0.5 );
> }
Thanks, another one for my wisdom collection.
> > and yes i know that (s)printf has methods to DISPLAY rounded numbers
> > but you can't put them in variables or process them.
> Yes you can. The printf() function is for displaying numbers, the
> sprintf() function is for stuffing numbers into variables, presumably
> for further processing.
It's quite tricky this "further" processing between the sprintf() commands you know?
> > The ceil() and floor() functions won't help me out either since the
> > server i run my scripts on does not have the perl.pm module around
> The "perl.pm" module? Never heard of it. Or do you mean the POSIX
> module?
Yups, sorry (it's late for me so i'm not too awake).
> > neither am i capable of getting this thing going there myself (when
> > adding it in my own cgi-bin directory) so anything i need to call with
> > 'use' is being interpreted as an error. I really need a solid nearing
> > function that rounds up to the nearest number
> *Up* to the nearest number? That would be a ceil() function, I guess:
nopes sorry, just rounding to the nearest number which is <0.5 is int and >= 0.5 is rounding up.
In financial aspects the rounding factor is determined by the third decimal minimum.
> sub ceil {
> my $x = shift;
> my $ix = int $x;
> return $x <= 0 || $x == $ix ? $ix : $ix + 1;
> }
the server logs errors on the 'use POSIX;' line so this option is out unless i ask the sysad to update their
perl packages. I believe they have a very simple stripped and bald version of perl with own security patches
so that does not give me too much room to play with Perl.
Some sysads are so damn afraid one of their users cause leaks and hack-attacks with their perl script.
This is why i started fiddling with int in the first place.
> > which is not too hard to make but i can't make this one if the float
> > engine is not reliable.
> The floating point engine is reliable, you just have to be aware of its
> limitations.
> > As i want to make notice that this is for financial purposes which do
> > need a quite precise output and processing so i guess this bug
> > propbably did not went unnoticed.
> It's not a bug.
no, it's the FPU that is not capable of calculating correctly but that's not the fault of Perl if i understand
it correctly.
> > Does anyone else get the same result in his/her version of Perl?
>
> Yup.
So i did not screw up my Perl installation....
sigh....
Thanks and regards,
Vv.
------------------------------
Date: 4 Jun 2000 00:56:00 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: floating point algorithm bug in perl 5.6.0?
Message-Id: <8hc9f0$fcg$1@slb6.atl.mindspring.net>
Vincent Voois (vvacme@worldonline.nl) wrote:
: As i want to make notice that this is for financial purposes which do need a quite precise output and
: processing so i guess this bug propbably did not went unnoticed.
Others have told you why you're getting the results you are, but haven't
pointed out that when doing financial calculations it's strongly advisable
to do all your actual computations in whole numbers of the smallest
currency units you deal with (e.g. cents for US currency where no prices
involve fractions of a cent) and convert to larger units (e.g. dollars)
only when doing output. That prevents roundoff losses from accumulating.
------------------------------
Date: Sat, 3 Jun 2000 19:29:05 -0500
From: Duke Banerjee <sfighter@cs.utexas.edu>
Subject: How do you pass a hash reference in Perl 4?
Message-Id: <Pine.GSO.4.21.0006031914350.9012-100000@cheddar.cs.utexas.edu>
Hi!
I'm trying to pass a hash to a function via a reference. Here's an
example of what I'm trying to do:
$myhash{"bob"} = "here";
&myfunc( \%myhash );
sub myfunc {
local ( *myhashref ) = @_;
print $myhashref{"bob"};
}
The output of this program in Perl 5 is:
here
But, there's no output in Perl 4 and perl tells me that I've got a
spurious backslash at the function call.
I'd appreciate any suggestions. Thanks!
Duke Banerjee
sfighter@cs.utexas.edu
------------------------------
Date: Sun, 04 Jun 2000 03:01:37 +0200
From: Vincent Voois <vvacme@worldonline.nl>
Subject: Re: How do you pass a hash reference in Perl 4?
Message-Id: <3939AA71.AECE5867@worldonline.nl>
> Hi!
>
> I'm trying to pass a hash to a function via a reference. Here's an
> example of what I'm trying to do:
>
> $myhash{"bob"} = "here";
>
> &myfunc( \%myhash );
>
> sub myfunc {
>
> local ( *myhashref ) = @_;
>
> print $myhashref{"bob"};
>
> }
>
> The output of this program in Perl 5 is:
>
> here
>
> But, there's no output in Perl 4 and perl tells me that I've got a
> spurious backslash at the function call.
I believe prototypes and reference arguments were supported from Perl 5.002, not 4.
What would you need Perl 4 for anyway?
Vv.
------------------------------
Date: 4 Jun 2000 00:59:29 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: How do you pass a hash reference in Perl 4?
Message-Id: <8hc9lh$fcg$2@slb6.atl.mindspring.net>
Duke Banerjee (sfighter@cs.utexas.edu) wrote:
: I'm trying to pass a hash to a function via a reference. Here's an
: example of what I'm trying to do:
[snip]
: But, there's no output in Perl 4 and perl tells me that I've got a
: spurious backslash at the function call.
Very simple. That flea-bitten rotting camel carcass known as Perl 4
doesn't have references. They were introduced in Perl 5 seven years
ago. Seven years is a long time in computing. Methinks it's time to
upgrade (if upgrading requires the cooperation of someone else, remind
that someone that there are known security holes in all version of perl
prior to 5.004).
------------------------------
Date: Sat, 3 Jun 2000 22:23:06 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: How to escape "/"?
Message-Id: <3939e8b7.0@news.isholf.is>
"feng chen" <fchen@fas.harvard.edu> wrote in message
news:8hb7ki$vo6$1@news.fas.harvard.edu...
> Hi, There.
>
> How to escape "/"?
> For example, if I have a string "/usr/bin/" and I want to change
> it to "\usr\bin\". I am doing it this way:
> $ch = "/";
> $string =~ s/$ch/\\/;
>
> Are there any elegant ways?
>
if you dont mind LMS then use
$string =~ s/\//\\/g; # notice the 'g'
to avoid eye pain use:
$string =~ s_/_\\_g;
or
$string =~ s(/)(\\)g;
but better is
$string =~ y:/:\\:;
gnari
> Thanks.
>
> Feng Chen
>
------------------------------
Date: Sun, 04 Jun 2000 09:56:22 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: Limits on $ENV{} hash ?
Message-Id: <39399B26.52E2@modulus.com.au>
Philip Taylor wrote:
>
snip]
> # this bit loads user specific config daa by reading a data file
> my $fname = $ENV{'RZ_DB_CONFIG'};
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
$fname contains something (never used)
> my $fname = '/home/taylorp/cgi-files/nwcsl/config.dat';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
$ fname now contains something else
> open (CONFIG, "< $fname");
[snip]
> The $ENV{} variables that are not loaded are those loaded by the WHILE
> loop above. I believe this is co-incidence and that it is something to
> do with a limit.
From your code I _suspect_ that you're reading an empty file - the file
may not even exist, since you don't check for the success of the system
call.
e.g.
open (CONFIG, "< $fname") || die "error opening $fname...$!";
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Sat, 03 Jun 2000 16:21:35 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Newbie in need of help...
Message-Id: <393992FF.913BE984@My-Deja.com>
> Hello,
> I want to test some cgi and perl scripts on my pc without logging on to the
> net. So, I downloaded apache for win98 and installed it, and what I want to
> know is if I need to have perl on my pc too for that to work ok?
yes.
--
------------------------------
Date: Sun, 04 Jun 2000 09:59:18 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: Newbie in need of help...
Message-Id: <39399BD6.3B1A@modulus.com.au>
MetSeed wrote:
>
> Hello,
> I want to test some cgi and perl scripts on my pc without logging on to the
> net. So, I downloaded apache for win98 and installed it, and what I want to
> know is if I need to have perl on my pc too for that to work ok?
> Thanks for your help.
Yes, as Perl != Apache.
http://www.activestate.com
is the place to find the most commonly used perl for PCs.
You'll also need to configure the Apache .conf files to make it all work
together.
Good luck!
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Sun, 04 Jun 2000 02:47:21 +0200
From: Vincent Voois <vvacme@worldonline.nl>
Subject: Re: Newbie in need of help...
Message-Id: <3939A719.B57D4F74@worldonline.nl>
You can also try http://www.sambar.com, sambar is a freeware HTTPD that is distributed with perl though it's
not the latest version of Perl, at least you can find out how perl is installed and executed in a HTTP daemon
environment and you can test your scripts in it's cgi-bin directory.
It is for sure a lot smaller than Apache.
Peter Hill wrote:
>
> MetSeed wrote:
> >
> > Hello,
> > I want to test some cgi and perl scripts on my pc without logging on to the
> > net. So, I downloaded apache for win98 and installed it, and what I want to
> > know is if I need to have perl on my pc too for that to work ok?
> > Thanks for your help.
>
> Yes, as Perl != Apache.
>
> http://www.activestate.com
> is the place to find the most commonly used perl for PCs.
> You'll also need to configure the Apache .conf files to make it all work
> together.
> Good luck!
> --
> Peter Hill,
> Modulus Pty. Ltd.,
> http://www.modulus.com.au/
Vv.
------------------------------
Date: 4 Jun 2000 00:10:53 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Not shifting what I want from an array
Message-Id: <8hc6qd$2m6fq$2@fu-berlin.de>
hi,
Craig Kelly <cekelly@dvol.com> wrote:
> After reading a text file into an array, I want to shift
> off each line of header stuff until I come to a line with
> the word "LINE" in it. The snippet below removes an arbitrary
> (too few) number of lines then exits the loop. Not what I
> expected. Worse, it behaves differently with different files
> that only vary by a coupla characters (never where it stops).
> @lines = <>;
> foreach (@lines)
> {
> last if ($_ =~ m/$key/);
> shift (@lines);
> }
just go over the code again and try to imagine what you're doing:
in the first loop you have something like:
last if ($lines[0] ...
then you shift. so the second element will
be at the first position ([0].
in the second loop you have:
last if ($lines[1] ...
but at position 1 is already the third element; the
second (which you want) is on position [0] so
you will never reach it;
so, you should not modify an array on which you are
doing a for-loop.
if you really want to have the file in an array
instead of doing
while (<>) {do something with $_}
then you may use the following while loop:
while(<@a>) {
last if m/$key/;
shift @lines;
}
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Sun, 04 Jun 2000 10:26:12 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: Predicted generation of ID numbers
Message-Id: <3939A224.B8C@modulus.com.au>
Andrej wrote:
>
> No problems, I have found a way to remove flock :-)
> Just
> ID,2; seek ID,0,0;
>
> Now I should add this code to basic script
>
> and use $id as
> $ENV{'RAND'} = $id;
>
> I tried
> --------------------------------
> sub Rnd {
my $id;
> $idfile = "id_num";
> if (open(ID,"+<$idfile")) {
> flock ID,2; seek ID,0,0;
> $id = <ID>; chomp($id);
> seek ID,0,0; print ID ++$id,"\n";
> close ID;
> } elsif (open(ID,">$idfile")) {
> $id = 400;
> flock ID,2; seek ID,0,0;
> print ID "$id\n";
> } else {
> print "Can't open $idfile: $!\n";
> exit;
> }
return $id;
> }
$ENV{'RAND'} = Rnd();
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Sun, 04 Jun 2000 00:41:30 GMT
From: "William Cardwell" <wellhaven@worldnet.att.net>
Subject: Problem using command line arguments
Message-Id: <_Ah_4.2180$2b4.140735@bgtnsc06-news.ops.worldnet.att.net>
I'm trying to read from the first file and write to the second file on the
command line, and supply a default file name when a command line file is
absent. I can't get it to work right for the output file. My latest test is
below. I'm thinking I shouldn't have to open the output file as I did below,
but how do I specify the file I am writing to? Can anyone help?
# -----This doesn't work
right-----------------------------------------------------
$ARGV[0] = 'infile.txt' unless $ARGV[0];
$ARGV[1] = '>outfile.txt' unless $ARGV[1];
open OUTFILE, "$ARGV[1]" or die "Can't open file $ARGV[1] for output: $!\n";
while(<>) {
$i++;
print OUTFILE "$i $_";
if ($i >= 2000) {last;}
}
close OUTFILE;
# --------------------------------------------------------------------------
--------
Thanks so much.
Will Cardwell
------------------------------
Date: Sun, 04 Jun 2000 03:03:52 +0200
From: Vincent Voois <vvacme@worldonline.nl>
Subject: Re: Problem using command line arguments
Message-Id: <3939AAF8.1B1835D2@worldonline.nl>
William Cardwell wrote:
>
> I'm trying to read from the first file and write to the second file on the
> command line, and supply a default file name when a command line file is
> absent. I can't get it to work right for the output file. My latest test is
> below. I'm thinking I shouldn't have to open the output file as I did below,
> but how do I specify the file I am writing to? Can anyone help?
>
> # -----This doesn't work
> right-----------------------------------------------------
> $ARGV[0] = 'infile.txt' unless $ARGV[0];
> $ARGV[1] = '>outfile.txt' unless $ARGV[1];
> open OUTFILE, "$ARGV[1]" or die "Can't open file $ARGV[1] for output: $!\n";
> while(<>) {
> $i++;
> print OUTFILE "$i $_";
> if ($i >= 2000) {last;}
> }
> close OUTFILE;
> # --------------------------------------------------------------------------
> --------
Did you tried below instead of your upper one?:
$ARGV[1] = 'outfile.txt' unless $ARGV[1];
open OUTFILE, ">$ARGV[1]" or die "Can't open file $ARGV[1] for output: $!\n";
Vv.
------------------------------
Date: Sun, 04 Jun 2000 10:40:18 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: Problems with MakeMaker om Win32 (ActiveState)
Message-Id: <3939A572.44DB@modulus.com.au>
Greg Thomas wrote:
>
> Greg Thomas wrote:
> > C:\temp> perl makefile.pl
> >
> > on everything I've downloaded, the procedure fails to find the
> > installation of Perl:
> >
> > Unable to find a perl 5 (by these names: C:\Perl\bin\Perl.exe miniperl
> > perl perl5 perl5.6.0, in these dirs: C:\WINDOWS C:\WINDOWS\COMMAND
> > C:\PERL\BIN C:\Perl\bin)
>
> Well, I've done a bit more digging. the problem appears to be in
> ExtUtils::MM_Win32.pm, and in particular in the area of:
>
> print "Executing $abs\n" if ($trace >= 2);
> $val = `$abs -e "require $ver;" 2>&1`;
> if ($? == 0) {
> print "Using PERL=$abs\n" if $trace;
> return $abs;
> } elsif ($trace >= 2) {
> print "Result: `$val'\n";
> }
>
> It turns out that although the backticks cause perl to executing
> "require $ver;" with no problems, $? is always set to -1. A further test
> shows that using backticks on just about any command results in $? eq
> -1.
>
> Unfortunately, that's about the limit of my knowledge. Any pointers
> gratefully received.
I'm not sure it's a great help, but execution of a command via backticks
returns what the command wrote to STDOUT (not, as you might be thinking,
a value indicating success or failure in a more predictable manner).
Thus any given program may produce any value.
hth
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Sat, 03 Jun 2000 23:37:34 GMT
From: "RGW303" <rgw303@mailandnews.com>
Subject: Re: using 'exists' in a program to test for keys in a hash
Message-Id: <2Fg_4.2890$Fe.87116@newsread2.prod.itd.earthlink.net>
Ok, I copied and pasted the Perl program the uses DB and compiled and I get
the same error. I get the error that DB_File module could be found in @INC
(c:\perl\lib) and low and behold it's not there. I've repaired and
reinstalled ActivePerl Build 613 several times. I've even uninstalled it and
reinstalled it but it won't show up. However, I do have the file
SDBM_File.pm in C:\perl\lib and when I use that program example that you
posted here (copied and pasted exactly as shown). I still the error:
"SDBM_File doesn't define an EXISTS method at myprog.pl line xx". (I made
sure exists was lowercase). If it makes any difference, I'm running Windows
98 SE.
Your help is appreciated,
-RGW303
Bob Walton <bwalton@rochester.rr.com> wrote in message
news:39395C9B.BF5215C7@rochester.rr.com...
> RGW303 wrote:
> >
> > Hello, I've just started learning Perl a few weeks ago and have gone
through
> > 2 books and for hours I've tried to successfully implement a method for
> > storing a retrieving keys and values in a hash DBM database. I'm using
> > ActivePerl 5.6. Anyhow my latest problem is testing for keys with the
> > 'exists' keyword after loading a hash from a DBM file with the dbmopen()
> > function. If I do the following anywhere in my code:
> >
> > while(exists $hash{"$key_$num"}) { <code...> }
> >
> > --or something just as similar with an if statement.--
> >
> > I get the error:
> >
> > "AnyDBM_File doesn't define an EXISTS method at myprog.pl line xx".
> You're not using uppercase for "exists", are you?
> >
> > Any help would be greatly appreciated.
> >
> > -RGW303
>
> Well, it works for me using ActiveState Perl build 613. Test code:
>
> use SDBM_File;
> use POSIX;
> tie(%h,'SDBM_File','junk136',O_RDWR|O_CREAT,0640) or die "Oops, $!\n";
> $h{one}=1;
> $h{two}=2;
> if(exists $h{one}){print "exists\n"}else{print "doesn't exist\n"}
>
> This prints "exists".
>
> You should note that SDBM won't work reliably on FAT or FAT32 file
> systems (a percentage of records written are not retrievable). That
> means you'll have to use DB_File on Windows 9x if you want it to work
> reliably. Besides, it saves four characters when typing the program:
>
> use DB_File;
> use POSIX;
> tie(%h,'DB_File','junk136',O_RDWR|O_CREAT,0640) or die "Oops, $!\n";
> $h{one}=1;
> $h{two}=2;
> if(exists $h{one}){print "exists\n"}else{print "doesn't exist\n"}
>
> Oh! I see ActiveState changed their dbmopen default to DB_File for
> version 5.6 . That's cool! Never mind about the SDBM stuff then.
> --
> Bob Walton
------------------------------
Date: Sat, 3 Jun 2000 23:49:47 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Viewing HTTP Requests
Message-Id: <Pine.GHP.4.21.0006032344060.1381-100000@hpplus01.cern.ch>
On Sat, 3 Jun 2000, Scott Mikula wrote:
> I was told this might be a good place to ask this question:
I suspect you have been slightly misinformed
> I am trying to write a perl script to automate some of my online activity,
> including reading and parsing web pages. Unfortunately I think the HTTP
> requests are more than just simple GETs because that doesn't work from my
> script; I assume they include more information, whether it be about cookies
> or something else.
I think you'd be more at home on comp.infosystems.www.authoring.cgi
where CGI and related matters are discussed, and where you'd find an
FAQ and in particular, reference to techniques for instrumenting and
debugging HTTP requests.
However, http://www.smithrenaud.com/public/CGI_MetaFAQ.html would
make a good start anyway.
This here is a good place to ask about Perl-specific things. But if
you want to know about HTTP requests and such, irrespective that you
intend to program them in Perl, it's considered more appropriate to
visit the places where HTTP requests are discussed. Be sure to make
the acquaintance of the relevant Perl modules.
Good luck.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3245
**************************************