[10524] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4116 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 31 03:07:18 1998

Date: Sat, 31 Oct 98 00:00:30 -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: 4116

Today's topics:
    Re: 0 - 1 toggling question (Snowhare)
    Re: 0 - 1 toggling question (Ronald J Kimball)
    Re: 0 - 1 toggling question <uri@sysarch.com>
    Re: array references  <krithikp@hotmail.com>
    Re: array references <krithikp@hotmail.com>
    Re: close() and the file pointer (Ronald J Kimball)
        Confused about objects in Perl <apollock@bit.net.au>
    Re: Cookie help (Larry Rosler)
    Re: easy way to learn perl? (Joel Rubin)
        Latest version for WindowsNT <arm@home.net>
    Re: Need help with OLE <nick@perlfect.com>
    Re: Not to start a language war but.. (Alan Barclay)
    Re: Not to start a language war but.. mravi@my-dejanews.com
    Re: perl art/puzzle (brian d foy)
        Perl for the mainframe? <ken.munro@ns.sympatico.ca>
    Re: psychology of language choice (was Re: language war <uri@sysarch.com>
    Re: scoping troubles (Ronald J Kimball)
    Re: SSI Random Image (Newbie??) <nick@perlfect.com>
        Static version of perl <dasilva@qualquer.elogica.com.br>
    Re: Syntactic flexibility (was: Re: psychology of langu <dgris@rand.dimensional.com>
    Re: Very Large DBM file: Finding Number of keys (Ronald J Kimball)
    Re: Very Large DBM file: Finding Number of keys (Ilya Zakharevich)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 30 Oct 1998 21:23:28 -0700
From: snowhare@xmission.xmission.com (Snowhare)
Subject: Re: 0 - 1 toggling question
Message-Id: <71e3c0$8d8$1@xmission.xmission.com>



Nothing above this line is part of the signed message.

In article <71doub$cnq$1@nnrp1.dejanews.com>,  <junsc@sysic.hei.co.kr> wrote:
>Hi, All
>
>I recently found out that negating a variable that has "1" does change its
>value to null, not "0". How can I easily change its value to "0". the
>operators "!", "not" and "~" all seem to change the value to null.

Assuming that $var has only the values '0' or '1':

$var = 1 - $var;

Benjamin Franz



Version: 2.6.2

iQCVAwUBNjqQsejpikN3V52xAQEeTAP+PPhWstz9+oGQaOeYgEl1P/0Jbz7DtzFy
9yrXEzLofMalNEcnBvl/epCfEQtZ557usirq1LIuMGSGp+qkog20hKG0K+mrphTQ
bIlhrL6alGna+LOvGj34rVTHDsKicvDxr6d+GfbwmTxyVnGQmYXdfY2pE4VmwY5+
rN3+OplyO7M=
=IKSC
-----END PGP SIGNATURE-----


------------------------------

Date: Fri, 30 Oct 1998 23:44:41 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: 0 - 1 toggling question
Message-Id: <1dhqgh6.tlernc1nf1ivoN@bos-ip-1-96.ziplink.net>

<junsc@sysic.hei.co.kr> wrote:

> I recently found out that negating a variable that has "1" does change its
> value to null, not "0". How can I easily change its value to "0".

$toggle ^= 1;

Bitwise exclusive or.

-- 
 _ / '  _      /         - 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 00:16:16 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: 0 - 1 toggling question
Message-Id: <x767d1e2fz.fsf@sysarch.com>

>>>>> "RJK" == Ronald J Kimball <rjk@coos.dartmouth.edu> writes:

  RJK> <junsc@sysic.hei.co.kr> wrote:
  >> I recently found out that negating a variable that has "1" does
  >> change its value to null, not "0". How can I easily change its
  >> value to "0".

  RJK> $toggle ^= 1;

  RJK> Bitwise exclusive or.

ronald,

you beat me to the punch. this is my idiom too. i think it is the best
way assuming only 1 and 0 are wanted.

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, 31 Oct 1998 14:50:44 +0800
From: Rakesh Puthalath <krithikp@hotmail.com>
Subject: Re: array references 
Message-Id: <363AB344.EA8915EA@hotmail.com>

I overlooked .... here's the code ..

#!/usr/bin/perl -w
open(FILE,"/etc/passwd") or die "Unable to open file \n";
@lines = <FILE>;
print @{\@lines};
close(FILE);
 

Rick Delaney wrote:

> [posted & mailed]
>
> nguyen.van@imvi.bls.com wrote:
> >
> > Hi guys,
> >
> > I want read a file with each line is assigned as an array reference
> > and also want to print out all of them. Please give me a general
> > format.
>
> perldoc perllol
>
> --
> Rick Delaney
> rick.delaney@shaw.wave.ca

 



------------------------------

Date: Sat, 31 Oct 1998 14:37:06 +0800
From: Rakesh Puthalath <krithikp@hotmail.com>
Subject: Re: array references
Message-Id: <363AB012.430BED5D@hotmail.com>

#!/usr/bin/perl -w
open(FILE,"/etc/passwdt") or die "Unable to open file \n";
@lines = <FILE>;
close(FILE);
foreach ( @lines)
{
  print $_;
}

Hope this helps ..

Rakesh
Rick Delaney wrote:

> [posted & mailed]
>
> nguyen.van@imvi.bls.com wrote:
> >
> > Hi guys,
> >
> > I want read a file with each line is assigned as an array reference
> > and also want to print out all of them. Please give me a general
> > format.
>
> perldoc perllol
>
> --
> Rick Delaney
> rick.delaney@shaw.wave.ca

 



------------------------------

Date: Fri, 30 Oct 1998 23:44:42 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: close() and the file pointer
Message-Id: <1dhqgsm.tfuofy1uep008N@bos-ip-1-96.ziplink.net>

David Proffitt <d.m.proffitt@mds.qmw.ac.uk> wrote:

> Has anyone come across any circumstances where an explicit close on a file
> handle doesn't reset the file pointer to the first line?

>From perlvar:

  $.

  The current input line number for the last file handle from
  which you read (or performed a seek or tell on).  An
  explicit close on a filehandle resets the line number.

I am inclined to think that the problem in your program lies elsewhere.

> [...]

> this works fine the first time it is called but any subsequent calls exit
> immediately - i did get it to print out the value of $. and it is reading
> through the correct number of lines on the first pass then none at all on
> the second so i am assuming that the problem is related to the pointer
> sticking at eof

The value of $. is not a pointer into the file.  It is simply the number
of times that <FILEHANDLE> has been called.  It cannot cause the problem
you described.

I can't tell you more without seeing more of your program.

-- 
 _ / '  _      /         - 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 15:24:58 +1000
From: "Andrew Pollock" <apollock@bit.net.au>
Subject: Confused about objects in Perl
Message-Id: <71e6v9$jfp$1@news.bix.asn.au>

I admit it, objects in Perl confuse me. I can use them in other languages,
but when it comes to Perl I get really confused really quickly.

My confusion stems from methods vs properties. Basically, I can't figure out
properties of objects under Perl. All the objects seem to have methods, but
no properties.

For example, I'm playing with Perl under Win32, trying to do some database
access using ADO.

Here's what I'd write in VBScript:

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("databasedsn")
Set oRs = Server.CreateObject("ADODB.RecordSet")
Set oRs.ActiveConnection = oConn

Note the last line above. ActiveConnection is a _property_ of
ADODB.RecordSet. It takes an ADODB.Connection object.

This is how I'd assume I'd write the equivalent thing in Perl:

Use OLE;

$oConn = .CreateObject OLE "ADODB.Connection";
$oConn->Open("databasedsn");
$oRs = CreateObject OLE "ADODB.RecordSet";
$oRs->ActiveConnection = $oConn;

(Somewhat) understandably, this falls over, with Perl barfing about
Can't modify subroutine entry in scalar assignment at callview.pl line 23,
near "$oConn;"

I'm assuming this is because Perl is expecting me to be talking about a
method, not a property. How do I reference object _properties_ under Perl?

I know I'm missing something (probably major) in my knowledge of OOP under
Perl. Anyone care to point out what it is?

Thanks in advance

Andrew



------------------------------

Date: Fri, 30 Oct 1998 19:35:04 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Cookie help
Message-Id: <MPG.10a425425719b259898f8@nntp.hpl.hp.com>

In article <MPG.10a3e15cf11f18c6989853@nntp.hpl.hp.com> on Fri, 30 Oct 
1998 14:45:26 -0800, Larry Rosler <lr@hpl.hp.com> says...
 ...
> > The delimeter is \1 and it prints as 
> ...
> > Does anyone out there know how I can yank these kind of values out of the
> > cookie?  Any help would be greatly appreciated.
> 
> @fields = split /\1/, $line;

Oops.  Tom Phoenix graciously pointed out that, whereas either "\1" or 
"\01" represents control-A in the double-quoted context of a string, one 
needs /\01/ in the *regex* context of a split.  From perlre:

    (\1 through \9 are always backreferences.) 

I mis-thought that -- like \10 etc. -- they were backreferences only if 
there was something to backrefer to.

Perl's context-sensitive grammar strikes again.  I'll add that to my 
ever-lengthening 'got-me' list...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Sat, 31 Oct 1998 03:14:37 GMT
From: jmrubin@ix.netcom.com (Joel Rubin)
Subject: Re: easy way to learn perl?
Message-Id: <3640809b.3047858@nntp.best.ix.netcom.com>

On Thu, 29 Oct 1998 20:41:53 +0100, "Bibliotek"
<olavskolen.bibliotek@hl.telia.no> wrote:

>is it any web sites wher newbies can learn peral eas`?
>whgat is stronges off java script and perl sdscript
>
You might want to register for Macmillan's bookshelf service. You get
90 days free access to any of the books in their collection.
(including some books on Perl) In exchange. you get a bit of semi-spam
from them. (strictly speaking, it isn't spam since you opt in and get
a service in exchange for receiving it)

http://www.mcp.com


==========
It would probably NOT be a very good idea for a spammer to harvest
the following addresses:

<root@warez.phantom.com>
<postmaster@warez.phantom.com>
<webmaster@warez.phantom.com>


------------------------------

Date: Sat, 31 Oct 1998 03:24:11 GMT
From: Alan Melton <arm@home.net>
Subject: Latest version for WindowsNT
Message-Id: <363A8123.689E2BDC@home.net>

What is the latest version for Windows NT
and is dbmopen and dbmclose
supported and where can I find the
documentation for the WinNT release for
these functions or what is an example of
how the function is used if it is supported.
Thanks
Alan Melton


------------------------------

Date: Sat, 31 Oct 1998 05:26:38 +0000
From: Nick Moraitakis <nick@perlfect.com>
Subject: Re: Need help with OLE
Message-Id: <363A9F8E.3F52FC24@perlfect.com>

Alastair wrote:

> Chad Moston <chad@anlon.com> wrote:
> >I have searched extensively to find documentation on the web about OLE
> >and have come up short.  Can anyone send me some URL's of some good
> >sites to get me started with this?
> >
> >I appreciate the help.
>
> I went to one of the big search engines and typed in 'OLE' and found '248050'
> web pages.
>
> What has this got to do with Perl?

I think he means the Win32::OLE module, to do OLE in NT Perl. There was a pretty
informative article in Perl Journal issue 8 or 9 I think...

--
Nick Moraitakis
http://perlfect.com



------------------------------

Date: 31 Oct 1998 03:31:29 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Not to start a language war but..
Message-Id: <909804671.389365@elaine.drink.com>

In article <36398c21.160788@read.news.global.net.uk>,
Dave Kirby <dkirby@see.sig.for.addr> wrote:
>I and many others have stated that they found python easier to learn
>than perl, but no-one who has learnt both languages has said they
>found perl easier to learn.  As for not sacrificing any power, can you

Ok, I'll say it.

I found perl easier to learn.

I'd been programing in sed,awk,shellscript etc for years, downloaded perl3
from comp.sources.misc, and played around. Within a very short time, I was
writing programs, with only the occasional reference to the man page in
order to remind myself of the order of arguments to a function call.

I installed python on one system this year, bought the O'Reilly python
book, and did a combination of reading the book, trying example code
off the net, and writing my own.

Things that made learning perl easier than learning python:
	Perl reused syntax I was familiar with. $variable is common
	to shell, awk & perl,` is common to shell & awk. Regex's are
	common to grep,awk & perl.

	More than one way to do things means that I could choose ways
	that I was comfortable with. I didn't know you could do 'foreach'
	for quite a while, and would always do "for($i=0;$i<($#array);$i+)
	{something}". I know now it's often not the best way to do things,
	but while i was learning I could use that familiar construct.

	A consistant name space meant I could steal code before I really
	understood it. When trying python, I'd sometimes see code, copy
	it into another program, and find I couldn't get it to run. I
	now know that this is due to the import statements, but to a
	beginner this was very confusing.

	{}. The majority of languages I program in uses {} to mark blocks.
	eg Java, C, C++, perl, awk. Becuase of this, the editor I use has
	nice features which make programming in these languages easier.
	I don't have to think about indentation, I just hit a { or a },
	and I'm automatically indented or outdented. If I decide to add
	some {} to existing code, I can hit a couple of keys and modify
	the indentation for that block. Even those languages that don't
	use {} as block markers typically use keywords to do the same
	thing (BEGIN,END/PROC,ENDP etc). I think even python's supporters
	have to admit that marking blocks by indentation is a very unusual
	thing for a language to do, and when you are learning a new language,
	it's the unsusual things that trip you up.
	
	The quality of the documentation. Perl's man page has always been
	very good. I learnt perl from it, as did many others. I've only
	seen the man page from python 1.5, but no way could I learn anything
	from it. 


------------------------------

Date: Sat, 31 Oct 1998 07:49:51 GMT
From: mravi@my-dejanews.com
Subject: Re: Not to start a language war but..
Message-Id: <71efev$7oo$1@nnrp1.dejanews.com>

Hi all,  I've been following this language war thread for sometime and the
whole thing has been alot of fun and occasionally educational.But why doesn't
everyone agree to a cease fire and go back to whatever they were doing before
this started?(writing code maybe? :-D ). This is looking more and more like a
"Which is a better lnguage French or German ? " kind of debate? Why don't we
focus less on which language is being used for coding and more on *what* is
being coded? A focus on th relative ease/difficulty of coping with *real
life* problems would be nice... It's not as if anybody is being forced to
adopt one language or the other. Choose what works for you in a particular
context and use it.Why argue? My two cents worth.... YMMV, Regards, Ravi

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Sat, 31 Oct 1998 01:10:03 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: perl art/puzzle
Message-Id: <comdog-ya02408000R3110980110030001@news.panix.com>

In article <71dsi4$be5$1@pilot.njin.net>, dblack@pilot.njin.net (David Alan Black) posted:

> Puzzlewisely, the goal would be to write a useful program which
> completed the fourth side of the rectangle - though I do rather like
> the quasi-Escheresque effect.
>                                     ############
>                                     #          #
>                                     #          #
>                                     #          #
>                      print(join'',do{@n=<STDIN>#=~/([^,]+)/gx
>                  =~/([^,]+)/gx;map{my$r="";$_<$#n&&$n[$_]+1==$
>               n[$_+1]&&($n=$n||$n[$_])||($r.=$n#?"$n-$n[$_]"
>                     ?"$n-$n[$_]":$n[$_])&&($_<$#n)&&($r.=',')
>                            &&(undef$n);$r}(0..$#n)})
>                                     #          #
>                                     #          #
>                                     #          #
>                                     ############

along as gratuitous uses of ObPerl are allowed :)

                          ######################
                          #                    #
                          #                    #
                          #                    #
                          #                    #
                          #                    #
              print(join q##,  do{@n=<STDIN>=~m#([^,]+)#gx;$#=''
               ;map{my$r=$#;$_<$#n &&$n[$_]+q#1#==$n[$_+1].$#
               &&($n=qq#$n#||$n[$_])||  ($r.=qq#$n#?"$n-$n[$_]"
           :$n[$_])&&($_<$#n)&&($r.=',')&&($n=$#);$r}(0..$#n)})
                          #                    #
                          #                    #
                          #                    #
                          #                    #
                          #                    #
                          ######################

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


------------------------------

Date: Sat, 31 Oct 1998 03:34:49 GMT
From: Ken Munro <ken.munro@ns.sympatico.ca>
Subject: Perl for the mainframe?
Message-Id: <363A855B.80AD45E9@ns.sympatico.ca>

This may seem like an absurd question, but is there a port of the Perl
interpreter for the OS390 MVS IBM mainframe?

I've written a Perl script to process mainframe JCL. Can I run it on the
mainframe itself, rather than having to do some intermediary file
transfering?

Thanks.

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Ken Munro
ken.munro@ns.sympatico.ca
kenmunro@hotmail.com
http://www3.ns.sympatico.ca/ken.munro/




------------------------------

Date: 31 Oct 1998 00:11:09 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: psychology of language choice (was Re: language war ...)
Message-Id: <x790hxe2oi.fsf@sysarch.com>

>>>>> "MS" == Maciej Stachowiak <mstachow@mit.edu> writes:

  >> python types always talk about rigid structure, fixed indenting,
  >> consistant forms. this is a very academic view going back to the
  >> purest (in the minimalist way) language, lisp.

  MS> You must be on crack if you think _any_ dialect of lisp has "rigid
  MS> structure". Actually, the extremely simple syntax of lisp-like
  MS> languages offers some of the same kinds of benefits as perl's
  MS> highly complex and context-sensitive syntax, namely supporting
  MS> many programming idioms well. Perl does this by just having enough
  MS> syntax to support a bunch of them, Lisp does it by having using
  MS> the simple syntax to enable sufficient metalinguistic abstraction
  MS> facilities to express new idioms.

how did you figure out my drug habit so quickly?

IMO lisp is rigid by having such a simple syntax. i like infix
operators, and languages like c and perl which don't need a million
parens and prefix operators only. i don't like forth and postscript for
the same reason. my mind (and many others) have brains wired to used
infix. either this is from our early training in math or something
deeper it is a fact. this is a popular personal preference, as i know
lispers who think great in lisp. i can hack lisp when i want to (not
often) for emacs. but when i look at some long lisp modules, my eyes
glaze over. it seems impenetrable to me. and some parts like strings and
regexes are just wacko in lisp. you know how many backwhacks you need to
do anything reasonably powerful? one of my favorite parts of perl is the
syntactical flexibilty for all string type things. you have single
quoted, double quoted, execution, regex, here docs, and all can have
standard or custom delimiters. you choose your quotes according to
function and data context. if you need a string with double quotes, use
another delimiter. paired ones are great since they nest in the strings!
this is not academic (only ONE right way to have a string) but practical
real world design. strings can be hairy and are used so much so make it
easy to create them. perl does that. it makes easy things easy and hard
things possible.


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: Fri, 30 Oct 1998 23:44:44 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: scoping troubles
Message-Id: <1dhqi0j.1yezd0h1tn9lr4N@bos-ip-1-96.ziplink.net>

Ian Lowe <Ian_Lowe@fanniemae.com> wrote:

> Global symbol "crit" requires explicit package name at ./dfrev.pl line
> 36.
> Global symbol "warn" requires explicit package name at ./dfrev.pl line
> 38.

> I don't understand this.  I have predeclared the hashes.  Could someone
> offer me some insight into the problem?

>     36         system("$efm CRITICAL $class $host $owner{$fs}
> \"Filesystem $fs is over $crit% ($capacity{$fs}%)\"");


>     38             system("$efm WARNING $class $host $host \"Filesystem
> $fs is over $warn% ($capacity{$fs}%)\"");

Yes, you did predeclare the hashes %crit and %warn.

But $crit and $warn are not those hashes.  $crit and $warn are scalar
variables which have not been predeclared.

What did you really mean to do?


-- 
 _ / '  _      /         - 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 05:30:57 +0000
From: Nick Moraitakis <nick@perlfect.com>
Subject: Re: SSI Random Image (Newbie??)
Message-Id: <363AA091.14F6257F@perlfect.com>



Jim Haney wrote:

> here is my problem, how do I tag the html to access the cgi-bin (random
> image) file?

This is not a perl question.. better check with your web server's
documentation (or the FAQ of your web hosting provider) for the answer to
this.

Anyway, the answer probably is <!--#exec cgi="/cgi-bin/ssi_program"--> or
<!--#include virtual="/cgi-bin/ssi_program"-->

--
Nick Moraitakis
http://perlfect.com



------------------------------

Date: Fri, 30 Oct 1998 15:33:11 -0300
From: Gustavo Gibson da Silva <dasilva@qualquer.elogica.com.br>
Subject: Static version of perl
Message-Id: <363A0666.BA430D1@qualquer.elogica.com.br>

Hi,

I'm trying to get the compiler to generate a static version of perl. I'm
using gcc and eventhough I have the -static option added to ld's flag,
whenever I try to run it chrooted I get "not found". Is there any trick
on that?

	TIA,
		Gustavo.
-- 
"La Femme partage nos peines,
 double nos joies et triple
 nos depenses."


------------------------------

Date: 30 Oct 1998 20:22:57 -700
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Syntactic flexibility (was: Re: psychology of language choice (was Re: language war ...))
Message-Id: <m37lxhpg8e.fsf@rand.dimensional.com>

dkirby@see.sig.for.addr (Dave Kirby) writes:

> I just tried the following on my Win95 system (perl 5.004_2):
> 
>   DB<1> sub hello{ \
>   cont: print "hello world\n"; \
>   cont: }
> Got signal SEGV
> 
> C:\>

That's a bug.  Could you use the perlbug utility included with
your perl distribution to report it to the core developers.  Thanks.

> The same thing happened when I used qq. instead of ". What gives?

Can't tell you, as I don't have access to a Win32 box.  Perhaps
someone on p5p can provide an explanation after you report the
bug.

dgris
-- 
Daniel Grisinger              dgris@rand.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


------------------------------

Date: Fri, 30 Oct 1998 23:44:45 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <1dhqif4.1relptu1sigbqxN@bos-ip-1-96.ziplink.net>

Mark-Jason Dominus <mjd@op.net> wrote:

> >  In a scalar context, keys returns the number of elements of the hash
> >  (and resets the each iterator).  However, to get this information for
> >  tied hashes, including DBM files, Perl must still walk the entire
> >  hash, so it's not very efficient in that case.
> 
> Just because it's not efficient doesn't mean you can do any better.
> If you want to count something, you have to count it.

You've already pointed out (in another post) that for regular hashes and
keys() in a scalar context, Perl neither has to build a list nor count
the keys.  That sounds a lot more efficient to me than walking the
entire hash to get the number of keys, as Perl must do with tied hashes.

> In the case of internal hashes, Perl can count it as it goes along,
> but it still takes time.  The only reason it's a win is because Perl
> has to keep track of the count whether you want it or not.  It's like
> a nightclub with a free buffet.  The buffet is included in the cost of
> the admission, and you might as well eat it because you've already
> paid for it whether you wanted to or not.

It's also a win if you need the count more than once.  Walking the
entire hash each time you need the count is obviously less efficient
than incrementing and decrementing the count as the hash is modified,
and just fetching a value each time you need the count.

> In tied hashes, someone has to count them all over again.
> You could follow Russ'  suggestion:

[snip code having nothing to do with Russ's suggestion]

Russ suggested using one entry in the hash to store the number of keys.
When you add an entry to the hash, if the key did not previously exist,
increment $hash{TOTAL}.  When you need the number of keys, fetch
$hash{TOTAL}.

For example:

while (<>) {
  if (!$hash{$_}++) {
    $hash{TOTAL}++;
  }

  print "There are now $hash{TOTAL} unique keys.\n";
}


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.


Of course, since it's a tied hash, you could have the STORE and DELETE
methods maintain the value of $hash{TOTAL} for you.

-- 
 _ / '  _      /         - 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 05:54:08 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71e8m0$g55$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 <1dhqif4.1relptu1sigbqxN@bos-ip-1-96.ziplink.net>:
> 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.)

Ilya


------------------------------

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 4116
**************************************

home help back first fref pref prev next nref lref last post