[10528] in Perl-Users-Digest
Perl-Users Digest, Issue: 4120 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 31 15:07:19 1998
Date: Sat, 31 Oct 98 12:00:20 -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 Sat, 31 Oct 1998 Volume: 8 Number: 4120
Today's topics:
Re: 0 - 1 toggling question <r28629@email.sps.mot.com>
Re: 0 - 1 toggling question <r28629@email.sps.mot.com>
Re: 0 - 1 toggling question (Bart Lateur)
Re: 0 - 1 toggling question (Al Danial)
[HELP] Newbie question. <klo@mail2.intellect.com.tw>
Re: [HELP] Newbie question. (Matthew Bafford)
Base64 encoding problems on win32 (James W. Blackwell)
Cookie Rookie <rgl34@hotmail.com>
Re: How do you use the perl compiler? jorisdepaepe@my-dejanews.com
Re: How to copy files using system( ) in a Perl script <r28629@email.sps.mot.com>
Re: How to copy files using system( ) in a Perl script (Tad McClellan)
Multiple edits, multiple files <care227@ibm.net>
Re: Not to start a language war but.. (Richard Smol)
Re: Not to start a language war but.. (Richard Smol)
Re: scoping troubles <r28629@email.sps.mot.com>
Sx Hello World problem (Kjetil Kjernsmo)
tell with read/seek or with sysread/syseek (Bart Lateur)
Re: Testing Perlscript at home <a9609339@unet.univie.ac.at>
Re: the way to change directory in Perl script (Tad McClellan)
vec() (Matt Knecht)
Re: Very Large DBM file: Finding Number of keys (Ronald J Kimball)
Re: Very Large DBM file: Finding Number of keys (Ronald J Kimball)
Re: Very Large DBM file: Finding Number of keys (Ilya Zakharevich)
Re: Very Large DBM file: Finding Number of keys (Ilya Zakharevich)
Re: Very Large DBM file: Finding Number of keys (Ilya Zakharevich)
What's with these Curly brackets??? jhardy3747@my-dejanews.com
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 31 Oct 1998 09:08:49 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: 0 - 1 toggling question
Message-Id: <363B2801.F0751509@email.sps.mot.com>
Matthew Bafford wrote:
>
> In article <<3640ddfd.4281129@news.ping.be>>, bart.mediamind@ping.be
> (Bart Lateur) pounded the following:
> => Matthew Bafford wrote:
> => > $var = !$var+0;
> =>
> => I think I prefer
> =>
> => $var = !$var || 0 ;
> =>
> => I don't understand why your version doesn't give any warnings when run
> => under -w. It looks like !(expr) acts like a warning disabler.
> =>
> =>
> => $var = undef() + 0;
> => Use of uninitialized value at test.pl line 7.
> =>
> => $var = '' + 0;
> => Argument "" isn't numeric in add at test.pl line 8.
>
> Hmm...
>
> % perl -w-
> #!/usr/bin/perl -w
> $var = 1;
>
> for ( 1 .. 5 ) {
> $var = !$var+0;
> print "$var\n";
> }
>
> $var = 1;
> $var = ''+0;
> print "\n$var\n";
> __END__
> Argument "" isn't numeric in add at toggle line 12.
> 0
> 1
> 0
> 1
> 0
>
> 0
> % perl -v
> This is perl, version 5.005_02.
> ...
>
> What does yours do?
>
> => Bart.
>
> --Matthew
what happen to ^ operator?
-tk
------------------------------
Date: Sat, 31 Oct 1998 09:08:36 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: 0 - 1 toggling question
Message-Id: <363B27F4.EDC2D423@email.sps.mot.com>
Matthew Bafford wrote:
>
> In article <<3640ddfd.4281129@news.ping.be>>, bart.mediamind@ping.be
> (Bart Lateur) pounded the following:
> => Matthew Bafford wrote:
> => > $var = !$var+0;
> =>
> => I think I prefer
> =>
> => $var = !$var || 0 ;
> =>
> => I don't understand why your version doesn't give any warnings when run
> => under -w. It looks like !(expr) acts like a warning disabler.
> =>
> =>
> => $var = undef() + 0;
> => Use of uninitialized value at test.pl line 7.
> =>
> => $var = '' + 0;
> => Argument "" isn't numeric in add at test.pl line 8.
>
> Hmm...
>
> % perl -w-
> #!/usr/bin/perl -w
> $var = 1;
>
> for ( 1 .. 5 ) {
> $var = !$var+0;
> print "$var\n";
> }
>
> $var = 1;
> $var = ''+0;
> print "\n$var\n";
> __END__
> Argument "" isn't numeric in add at toggle line 12.
> 0
> 1
> 0
> 1
> 0
>
> 0
> % perl -v
> This is perl, version 5.005_02.
> ...
>
> What does yours do?
>
> => Bart.
>
> --Matthew
what happen to ^ operator?
-tk
------------------------------
Date: Sat, 31 Oct 1998 15:47:10 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: 0 - 1 toggling question
Message-Id: <363d306b.18307326@news.ping.be>
Matthew Bafford wrote:
>What does yours do?
The same. No warning, NEVER, for
$var = !$var + 0;
but warnings for both
$var = '' + 0;
undef $var; $var = $var + 0;
Argument "" isn't numeric in add at test.pl line 2.
Use of uninitialized value at test.pl line 3.
Bart.
------------------------------
Date: 31 Oct 1998 16:43:56 GMT
From: alnd@pacbell.net (Al Danial)
Subject: Re: 0 - 1 toggling question
Message-Id: <slrn73mfgp.6es.alnd@my.domain>
On Sat, 31 Oct 1998 15:47:10 GMT, Bart Lateur <bart.mediamind@ping.be> wrote:
>Matthew Bafford wrote:
>
>>What does yours do?
>
>The same. No warning, NEVER, for
>
> $var = !$var + 0;
>
>but warnings for both
>
> $var = '' + 0;
> undef $var; $var = $var + 0;
>
>Argument "" isn't numeric in add at test.pl line 2.
>Use of uninitialized value at test.pl line 3.
>
> Bart.
Adding zero seems goofy. Why not just use
$toggle = 1 - $toggle;
For example,
#!/usr/bin/perl -w
my $t;
$t = 1;
while (1) {
$t = 1 - $t;
print "$t\n";
}
gives a convincing stream of 0, 1, 0, 1, etc. -- Al
------------------------------
Date: Sun, 01 Nov 1998 02:10:02 +0800
From: Kevin Lo <klo@mail2.intellect.com.tw>
Subject: [HELP] Newbie question.
Message-Id: <363B527A.21ACA33D@mail2.intellect.com.tw>
Hi,
I'm a new to Perl. I don't know the following codes what it means,
hope anyone can explain to me, thanks.
open(CFG, 'config');
while (<CFG>) {
($var, $val) = split;
$$var = $val;
}
P.S. What's 'CFG'?
Thanks in advance,
Kevin.
------------------------------
Date: Sat, 31 Oct 1998 13:32:57 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: [HELP] Newbie question.
Message-Id: <MPG.10a521e6be9e45a69896f7@news.scescape.net>
In article <<363B527A.21ACA33D@mail2.intellect.com.tw>>,
klo@mail2.intellect.com.tw (Kevin Lo) pounded the following:
=> Subject: [HELP] Newbie question.
Before your next post, please make sure to visit the following site.
Following the instructions there will improve your chances at getting
your questions answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
=> Hi,
=>
=> I'm a new to Perl. I don't know the following codes what it means,
=> hope anyone can explain to me, thanks.
You really should RTFM[1], but...
=> open(CFG, 'config');
Open the file config for reading. The filehandle CFG is used to
access it. If this command fails, you won't know why because there is
no check of the return value from open.
open CFG, 'config' or die "Can't open config, because: $!\n";
would be much better.
=> while (<CFG>) {
Grab each line of config (in this case), and store it in $_.
=> ($var, $val) = split;
Spilt $_ on the first whitespace into two strings, ignoring everything
after the first two nonwhitespace groups.
Given:
Just another perl hacker,
$var now equals 'Just',
$val now equals 'another'.
=> $$var = $val;
Use soft references to assign the value of $val to the variable of the
name stored in $var. Ie, $Just now equals 'another'.
This isn't a very good way of going about it... Hashes are much
cleaner and safer.
=> }
=>
=> P.S. What's 'CFG'?
The filehandle.
The above example would be much better written as:
my %vars;
open CFG, 'config' or die "Unable to open 'config', reason: $!\n";
while ( <CFG> ) {
my ( $varname, $value ) = split " ", $_, 2;
$vars{$varname} = $value;
}
close CFG or die "Unable to close 'config', reason: $!\n";
=> Thanks in advance,
HTH,
=> Kevin.
--Matthew
1: Read the (free|fine|fishing) manual!
------------------------------
Date: Sat, 31 Oct 1998 19:29:51 GMT
From: jamesb@lsg.net (James W. Blackwell)
Subject: Base64 encoding problems on win32
Message-Id: <363b63e5.602645648@news.etex.net>
Greetings,
I'm trying to encode a binary file on a win32 machine. Using the
sample code that is included with mime:base64 this should work.
However, after it reads the first chunk of the file and encodes it, it
stops.
I know when I reversed the process, I had to use binmode to tell my
decoder to output a binary file. I'm sure there's something very
basic that I'm missing here.
use MIME::Base64 qw(encode_base64);
$myfile="c:\\temp\\testfile.zip";
open(FILE, $myfile) or die "$!";
while (read(FILE, $buf, 60*57)) {
print encode_base64($buf);
}
Any help would be greatly appreciated.
Thanks,
--James
------------------------------
Date: Sat, 31 Oct 1998 08:29:23 -0800
From: "Robert Long" <rgl34@hotmail.com>
Subject: Cookie Rookie
Message-Id: <71fdoa$q3f$1@pollux.dnai.com>
I have been programming in Perl for over a year, but I have never had the
need or opportunity to deal with cookies. I need to construct a cookie and
deliver it to the users browser, later check for the cookie.
The question I have, is how is the delivery of the cookie done? I believe
the construction and retrieval of this cookie to be pretty basic. But for
some silly reason, I do not know how to deliver it.
Any help in this is appreciated. If you know of some resources I can check
on line through a News group, that would also be great.
Thanks
------------------------------
Date: Sat, 31 Oct 1998 17:54:16 GMT
From: jorisdepaepe@my-dejanews.com
Subject: Re: How do you use the perl compiler?
Message-Id: <71fis9$jeo$1@nnrp1.dejanews.com>
In article <2CD4D1A956A0D111B04100805F6F312CBA64E6@email.ile.com>,
Chris Anderson <ChrisA@ile.com> wrote:
> I have the ActiveState Perl v5.00.502 on Windows 95 (I've also tried on
> NT 4.0) and I can't get the compiler to work. All the documentation I've
> seen makes it sound pretty idiot proof- just type "perlcc a.pl" and
> you'll get an executable. So, I guess I'm an idiot because it's not
> working. The perl syntax checks out OK, and it creates the code but
> chokes on compiling with the message "Couldn't open !"- it's missing a
> filename in the error message.
> It seems like there must be some setup required (and I'm guessing that's
> what I'm missing), but I haven't seen any documentation on that.
> Any help would be appreciated
>
> Thanks,
> Chris
>
>
I have exactly the same problem (altough I installed perl 5.005 from the Perl
Resource Kit Win32 Edition), do you have already founf a solution ? If so,
please let me know (jdp@schaubroeck.be).
Thanks,
Joris
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 31 Oct 1998 09:01:47 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Liew Fook Sin <lfs97@tm.net.my>
Subject: Re: How to copy files using system( ) in a Perl script
Message-Id: <363B265B.CA859AAF@email.sps.mot.com>
Liew Fook Sin wrote:
>
> Hai,
s/Hai/Hi/;
> I need to copy a file from a particular location to another location using
> a cgi written in Perl.
> I have tried the following command but it didn't work
>
> #! /usr/bin/perl
>
> $filename = "/path/some_filename";
> $destination_filename = "/path/another_filename"
> system (cp $filename $destination_filename);
>
> Can anyone, please help.
> Thanks a lot
>
> Liew
> exit;
Why are you posting the same question again? If you don't care to check
the reply, then stop posting here.
-tk
------------------------------
Date: Fri, 30 Oct 1998 20:05:09 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to copy files using system( ) in a Perl script
Message-Id: <l8rd17.921.ln@flash.net>
Liew Fook Sin (lfs97@tm.net.my) wrote:
: I need to copy a file from a particular location to another location using
: a cgi written in Perl.
: I have tried the following command but it didn't work
: #! /usr/bin/perl
: $filename = "/path/some_filename";
: $destination_filename = "/path/another_filename"
: system (cp $filename $destination_filename);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1) you are either missing some quotes there, or using
a bareword and missing some commas...
2) check the return value from system()
3) ensure that you have permission for whatever the current
directory is
4) use -w
5) find out where your server error logs are, and see if
there is output there
if (system "cp $filename $destination_filename")
{die "could not copy $!"}
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 31 Oct 1998 14:35:10 -0500
From: Drew Simonis <care227@ibm.net>
Subject: Multiple edits, multiple files
Message-Id: <363B666E.3F222173@ibm.net>
This is a multi-part message in MIME format.
--------------49A0D92D14F8B6CDEB837F40
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
--------------49A0D92D14F8B6CDEB837F40
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-ID: <363B4A7C.5807DAF@ibm.net>
Date: Sat, 31 Oct 1998 12:35:56 -0500
From: Drew Simonis - US Internet Support <care227@ibm.net>
Reply-To: care227@ibm.net
Organization: IBM Global Services/NS
X-Mailer: Mozilla 4.04 [en] (Win95; U)
MIME-Version: 1.0
Newsgroups: comp.editors,comp.lang.awk,comp.perl.misc
Subject: Multiple edits, multiple files
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 198.133.22.195
X-Trace: 31 Oct 1998 17:36:47 GMT, 198.133.22.195
X-Notice: Items posted that violate the IBM.NET Acceptable Use Policy
X-Notice: should be reported to postmaster@ibm.net
X-Complaints-To: postmaster@ibm.net
Path: news3.ibm.net!198.133.22.195
Xref: news3.ibm.net comp.editors:23792 comp.lang.awk:8576
I have a bit of an issue... first, to invoke some sympathy, some
background.
I recently inherited a web site from a departed co-worker. I am now
responsible for over 800 pages of content. Make that 800 pages of
content lacking ISO-9000 document control pages. I have 3 days to add
this information to these pages or else!
So here's what I have...
I need a script (awk, sed, perl or shell) to do the following, and I am
having alot of difficulty (a newbie to scripting here)
In psuedo code:
take the value located between the <title> and </title> and hold it.
Search for </body> and replace it with:
Name of the document: RECALL STORED VALUE HERE
Owner of document: Manager Department PT4
Required approvals: Manager Department PT4
This document was last updated on: Oct. 31 1998
This document is located on: url stuff here
Distribution list: Department PT4
Document control:
Records retention period for this document is for one year or until it
is no longer required. (Example: replacement procedure or an
organizational change render this document no longer a necessity in
meeting business needs)
Users of this document can recommend changes by contacting the owner.
The owner of this document is the only individual authorized to make
changes to this document.
The owner will ensure all users of this document are made aware of any
changes, additions, or deletions. This includes complete deletion of a
document.
Revision Change History for RECALL STORED VALUE AGAIN
Revision dates:
Original issue date: June 15, 1998
Approved by: Manager Department PT4
Change history:
Revision 1 changes:
</body>
I need to make these changes to 800 documents and then write the edits
back to the origional document. Can anyone help? Point me in the
correct direction?
At least pity me?
Drew
--------------49A0D92D14F8B6CDEB837F40--
------------------------------
Date: 31 Oct 1998 17:20:09 GMT
From: bl227@cleveland.Freenet.Edu (Richard Smol)
Subject: Re: Not to start a language war but..
Message-Id: <71fgs9$gu0$1@pale-rider.INS.CWRU.Edu>
In a previous article, tchrist@mox.perl.com (Tom Christiansen) says:
>Our written expressions (you know: prose and such) are saddled with
>ludicrous capital letters, apostrophes, commas, periods, colons, and
>dashes -- not to mention parentheses. Who cares whether the result is
>an illegible mess?
There is a big difference between prose and a computer program. With prose,
the meaning of the text is included in the text itself. With a
computer-program, the meaning is actually what a piece of code DOES.
In Perl, it can be quite a tedious job to find out what kind of task a
certain piece of code carries out. It is much clearer in Python, where
there are numerous constructs that help the reader of a program out... plus
that the code isn't cluttered with characters like {, }, @, $ or whatever.
I have done siginificant work in both Perl and Python, ranging from
web-stores to large SGML/XML document management systems. I always found the
Perl-code much harder to maintain than the code in Python.
Greetz,
RS
------------------------------
Date: 31 Oct 1998 18:15:14 GMT
From: bl227@cleveland.Freenet.Edu (Richard Smol)
Subject: Re: Not to start a language war but..
Message-Id: <71fk3i$r0q$1@pale-rider.INS.CWRU.Edu>
In a previous article, uri@sysarch.com (Uri Guttman) says:
>>>>>> "JL" == James Logajan <JamesL@Lugoj.Com> writes:
>
> JL> P.P.S. What DO Perl programmers call themselves? Perlers?
> JL> Perlists? Something else? I think Python programmers are just
> JL> beginning to grapple with that issue, based on some recent
> JL> threads.
>
>it tells a lot about the origins of perl and the psychology of its
>users, that we proudly call ourselves perl hackers!
>
>what do python users call themselves? indentured anal(lysts)? :-)
>
We just call ourselves programmers ;)
------------------------------
Date: Sat, 31 Oct 1998 09:15:46 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: scoping troubles
Message-Id: <363B29A2.9256B928@email.sps.mot.com>
Ian Lowe wrote:
>
> I am fairly new to perl, and am having difficulty with the issue of
> scoping, for some reason. The following code returns the error
> messages:
>
> Global symbol "crit" requires explicit package name at ./dfrev.pl line
> 36.
> Global symbol "warn" requires explicit package name at ./dfrev.pl line
> 38.
>
[...]
> 1 #!/export/Tivoli/efmperl/bin/perl -w
> 2
> 3 use strict;
> 4 use Sys::Hostname;
> 5
> 6 my $host = hostname();
> 7 my $class = "FILESYSTEM_FULL";
> 8 my $date = localtime;
> 9 my (%size,%capacity,%owner,%warn,%crit);
[snip]
> 34 for $fs (keys (%capacity)) {
> 35 if ($capacity{$fs} > $crit{$fs}) {
> 36 system("$efm CRITICAL $class $host $owner{$fs}
> \"Filesystem $fs is over $crit% ($capacity{$fs}%)\"");
^^^^^^
what are you trying to do here?
> 37 } elsif ($capacity{$fs} > $warn{$fs}) {
> 38 system("$efm WARNING $class $host $host \"Filesystem
> $fs is over $warn% ($capacity{$fs}%)\"");
^^^^^^
what are you trying to do here?
> 39 }
> 40 last;
> 41 }
-tk
------------------------------
Date: 31 Oct 1998 19:50:31 GMT
From: kjetikj@ulrik.uio.no (Kjetil Kjernsmo)
Subject: Sx Hello World problem
Message-Id: <71fpm7$8hp$1@readme.uio.no>
Hi folks!
I have just tried to install Sx on my system, because somebody said it
was easier than Tk. Not without trouble, first I had to remove all the
Xaw3d-stuff I could find. Then, I haven't got access to the normal
installation directories, and I didn't want to bother my sysadm with
this stuff, so I installed it to a subdir of my home directory. The
installation seemed to go smoothly after those two modifications.
However, I'm unable to run the Hello world-program mentioned in the
manpage...! Doesn't sound good, eh...
If I run
#! /local/bin/perl5
use Sx;
OpenDisplay(@ARGV);
MakeLabel("Hello World!");
ShowDisplay;
MainLoop;
it goes:
Usage: Sx::OpenDisplay(args,...) at sxtest.pl line 4.
and if I do
#! /local/bin/perl5
use Sx;
OpenDisplay("My Window", @ARGV);
MakeLabel("Hello World!");
ShowDisplay;
MainLoop;
it goes "Segmentation fault", which is something that also happens if
I try to run SxDemo.pl.
I'm on a Digital UNIX osf1 V4 and my perl is 5.00404. I have tried
both cc and gcc when compiling.
Anybody got any ideas where I should start looking?
--
Vennlig Tiddeli-bom,
Kjetil
--
Kjetil Kjernsmo
Graduate astronomy-student Problems worthy of attack
University of Oslo, Norway Prove their worth by hitting back
E-mail: kjetikj@astro.uio.no - Piet Hein
Homepage <URL:http://www.astro.uio.no/~kjetikj/>
Webmaster@skepsis.no
------------------------------
Date: Sat, 31 Oct 1998 15:39:39 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: tell with read/seek or with sysread/syseek
Message-Id: <363c2c0e.17191360@news.ping.be>
I'm investgating JPEG images treating the files as binary files, and
reading/seeking the fields using read/seek/tell or sysread/sysseek/tell.
I'm not pleased with the fact that there are indeed two versions for
*read and *seek, but it's far worse than that: there is a potability
problem.
On my PC, I run Ilya's OS2 port on DOS. For this to work, I must use
syread and sysseek, because tell returns garbage if I use read/seek. For
example, I get negative results.
On the other hand, on my Internet account, which runs Linux (I don't
know the Perl port, except it's 5.004 something), sysread/sysseek is
unusable. There, I MUST use plain read/seek.
I hate this. I've ended up using:
$^O eq 'os2'?sysread(JPEG,$buffer,6):read(JPEG,$buffer,6);
and
$^O eq 'os2'?sysseek JPEG,$seek,0:seek JPEG,$seek,0;
This is horrible.
Can anybody tell me which port is wrong? Why the hell do we need both
anyway?
In the meantime, is there a better way to automatically select the right
one? I tried
if($^O eq 'os2') {
*doread = \&sysread;
} else {
*doread = \&read;
}
but this just won't work (it DOES compile, and run, though; I just can't
use doread.).
Bart.
------------------------------
Date: Sat, 31 Oct 1998 18:49:39 +0100
From: "Hakan Kilic" <a9609339@unet.univie.ac.at>
Subject: Re: Testing Perlscript at home
Message-Id: <71firs$8fse$1@www.univie.ac.at>
Sorry, I think I'm wrong here.
I wrote a CGI, which I want to test out at home. This CGI gets some Input
from a form.
All I wanted is:
Is there a programm to test CGI at home, without putting it on the web?
------------------------------
Date: Sat, 31 Oct 1998 12:07:20 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: the way to change directory in Perl script
Message-Id: <okjf17.0f5.ln@flash.net>
junsc@sysic.hei.co.kr wrote:
: How can I notify correctly the work directory to the script?
perldoc -f chdir
: One more thing, is there any PERL compilation option similar to "csh
: -fxv".[Verbose step by step execution]
perldoc perldebug
: Any information would be greatly appreciated.
You already had this information (it comes with perl).
Please use it.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 31 Oct 1998 19:54:50 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: vec()
Message-Id: <eWJ_1.47179$ZF.6885629@news3.voicenet.com>
I'm having problems trying to figure out how vec() works. I've tried
many variations on the following code.
my $bv = 0;
vec($bv, 0, 32) = 0;
# This gives me the expected 32 zeroes
print unpack("b32", $bv), "\n";
# Set low order bit
$bv |= (1 << 0);
# This gives me '10001100'
print unpack("b32", $bv), "\n";
I can't even begin to explain why oring with (1 << 0) or just a plain 1
give me '10001100'. Could somebody shed some light on what I'm doing
wrong here?
--
Matt Knecht - <hex@voicenet.com>
------------------------------
Date: Sat, 31 Oct 1998 12:01:57 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <1dhre7z.j2mti42sxbswN@bos-ip-1-107.ziplink.net>
Mark-Jason Dominus <mjd@op.net> wrote:
[snip overly simplified benchmark]
Your benchmark populates the hash, and then counts the keys once. I
said that maintaining the count is a win *if you need the count more
than once*. The two samples of code I provided counts the keys each
time a new key is added. The benchmark code you used counts the keys
once, after all the keys are added.
I cannot argue that your way is faster in that case, but that's not
really the case that I am interested in.
> >Russ suggested using one entry in the hash to store the number of keys.
>
> I thought I was doing Russ a favor when I replaced the hash entry with
> a separate scalar value. But sure, if you want it to take even longer
> to maintain the count, you go ahead and use that hash element.
There are two important points to Russ's suggestion.
First, the count is stored in the hash, meaning that it is persistent
and you don't need a separate count variable for each hash in the
program.
Second, by Russ's suggestion, adding elements to the hash and accessing
the count are both O(1) operations. With your suggestion, adding
elements to the hash is still O(1) but accessing the count is O(n).
Making a few modifications to the code you provided, I ran some new
benchmarks.
First, the modified code.
The dummy tied hash class is the same:
package Hash;
sub TIEHASH {
my $pack = shift;
bless {} => $pack;
}
sub FETCH {
$_[0]{$_[1]};
}
sub STORE {
$_[0]{$_[1]} = $_[2];
}
sub FIRSTKEY {
scalar each %{$_[0]}
}
sub NEXTKEY {
scalar each %{$_[0]}
}
The driver has changed, however:
$N = 10_000; # I think your system is faster than mine :-)
$M = shift; # how many times to count keys, from command line
tie %h => Hash;
my ($u1, $s1) = times;
for ($i = 0; $i < $N; $i++) {
#2# # Maintain the count
#2# if (! $h{$i}) {
#2# $h{TOTAL}++
#2# }
$h{$i} = $i;
}
for ($i = 0; $i < $M; $i++) { # new loop: count keys $M times
#2# get count from hash
#2# $c = $h{TOTAL};
#1# # Just count the keys all at once
#1# $c = scalar keys %h;
}
print "$c $N $M\n"; # $M added to output
my ($u2, $s2) = times;
my ($u, $s) = ($u2-$u1, $s2-$s1);
printf "u: %.2f; s: %.2f\n", $u, $s; # round off times :-)
exit 0;
Run the benchmark as before. Once with comments intact for a baseline,
once with #1# comments uncommented, and once with #2# comments
uncommented. Pass $M in on the command line. Results on my system:
$M=1 Baseline: u: 6.88; s: 0.28 total 7.16
#1# $M=1 scalar keys: u: 10.83; s: 0.33 total 11.16
#2# $M=1 Maintain count: u: 19.97; s: 0.38 total 20.35
Yup, as your benchmark showed, when $M is 1, scalar keys is twice as
fast as maintaining the count.
$M=10 Baseline: u: 7.10; s: 0.23 total 7.33
#1# $M=10 scalar keys: u: 43.38; s: 0.57 total 43.95
#2# $M=10 Maintain count: u: 19.87; s: 0.50 total 20.37
But what's this? Get the count just 10 times, and the situation has
completely reversed. Maintaining the count is now twice as fast as
scalar keys. In fact, the time for maintaining the count hasn't
significantly changed.
$M=100 Baseline: u: 7.08; s: 0.17 total 7.25
#1# $M=100 scalar keys: u: 372.82; s: 3.40 total 376.22
#2# $M=100 Maintain count: u: 20.42; s: 0.22 total 20.64
With $M set to 100, using scalar keys takes longer than 6 minutes, while
maintaining the count is still close to 20 seconds.
Based on further benchmarking, I discovered that you only have to count
the keys four times to make maintaining the code more efficient than
using scalar keys.
Of course, that's with a tied hash in memory. I imagine that with a DBM
file, the slowdown in scalar keys would be even more drastic.
Moral: With tied hashes, scalar keys is like candy. A little bit is
very good, but too much will make you sick.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 31 Oct 1998 12:02:00 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <1dhreqd.2g5gl6zu6b8wN@bos-ip-1-107.ziplink.net>
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:
> > I would bet a dime that, for tied arrays, that is faster than letting
> > Perl count them using 'keys' each time you need the count:
> >
> > while (<>) {
> > $hash{$_}++;
> >
> > print "There are now ", scalar keys %hash, " unique keys.\n";
> > }
> >
> > where scalar keys %hash contains an implicit loop over the entire hash.
>
> Since walking is performed in C, and setting is done in Perl, and
> speed difference of C and Perl is circa 200 times, please do some
> benchmarking before betting. (Walking is harder than just count++, so
> I would not try to guess what is an actual difference.)
If I'm not mistaken, the code above is O(n**2), whereas the code using
Russ's suggestion, that I was comparing it to, is O(n):
while (<>) {
if (!$hash{$_}++) {
$hash{TOTAL}++;
}
print "There are now $hash{TOTAL} unique keys.\n";
}
Still, if you insist... :-) I've posted a benchmark, in response to
MJD's benchmark, that proves my point.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 31 Oct 1998 17:24:20 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71fh44$75n$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Ronald J Kimball
<rjk@coos.dartmouth.edu>],
who wrote in article <1dhreqd.2g5gl6zu6b8wN@bos-ip-1-107.ziplink.net>:
> > > while (<>) {
> > > $hash{$_}++;
> > >
> > > print "There are now ", scalar keys %hash, " unique keys.\n";
> > > }
> If I'm not mistaken, the code above is O(n**2), whereas the code using
> Russ's suggestion, that I was comparing it to, is O(n):
Well, I did not look into this code. :-( It is indeed O(n^2), but I
would not write it this way ;-).
Ilya
------------------------------
Date: 31 Oct 1998 17:22:00 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71fgvo$74j$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Mark-Jason Dominus
<mjd@op.net>],
who wrote in article <71ek41$g08$1@monet.op.net>:
> What I said: What Russ said:
> > if (! $seen{$key}++) { if (++$UNIQUE_IPS{$ip} == 1) {
> > $total++; $UNIQUE_IPS{TOTAL}++;
> > } }
>
> One of us is missing the point here. I'll suppose it's me. What am I
> missing? They look the same to me.
Absolutely not. $a++ has much more overhead than ++$a, similar for
$UNIQUE_IPS{TOTAL} vs $total. Difference between is-true and ==1
should not be significant.
Ilya
------------------------------
Date: 31 Oct 1998 17:31:36 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71fhho$7gt$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Mark-Jason Dominus
<mjd@op.net>],
who wrote in article <71ejhe$fvh$1@monet.op.net>:
> sub NEXTKEY {
> scalar each %{$_[0]}
> }
> To benchmark this, run it once with the commesnts intact for a baseline.
Do not. This benchmark is absolutely meaningless since you did your
callbacks in Perl. The enourmous cost of Perl subroutine call makes
scalar keys number meaningless (though it should only improve the
final result).
> Baseline: u: 29.52; s: 0.25 total 29.77
> #1# scalar keys: u: 40.14; s: 0.31 total 40.45
> #2# Maintain count: u: 85.49; s: 0.20 total 85.69
Hope this helps,
Ilya
------------------------------
Date: Sat, 31 Oct 1998 18:22:14 GMT
From: jhardy3747@my-dejanews.com
Subject: What's with these Curly brackets???
Message-Id: <71fkgm$lm8$1@nnrp1.dejanews.com>
Whats the rules with the curly brackets. If I leave the sub below as is it
complains of syntax error at the last bracket. If I take it out it complains
that it is missing??
sub SQL_ProcedureINS
{
use OLE;
$Conn = CreateObject OLE "ADODB.Connection";
$Conn->Open("DSN=iHRS;UID=sa;PWD=");
$RS = $Conn->Execute ("dbo.CandidateINS \@RCODE='HeyGood', \@RNAME='Smarty'");
if(!$RS) {
$Errors = $Conn->Errors();
print "Errors:\n";
}
foreach $error (keys %$Errors) {
print $error->{Description},"\n";
}
die;
$RS->Close;
$Conn->Close;
}
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4120
**************************************