[12068] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5668 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 15 01:07:16 1999

Date: Fri, 14 May 99 22:00:15 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 14 May 1999     Volume: 8 Number: 5668

Today's topics:
    Re: Hash arrays armchair@my-dejanews.com
    Re: Hash arrays armchair@my-dejanews.com
    Re: Hash arrays armchair@my-dejanews.com
    Re: Hash arrays <tchrist@mox.perl.com>
    Re: Hash arrays <tchrist@mox.perl.com>
    Re: Hash arrays (Sam Holden)
    Re: Hash arrays (Sam Holden)
    Re: man pages and FAQs: why posted? <elaine@cts.wustl.edu>
        Parameter pass to PERL (Raymond Ip)
    Re: Perl "constructors" <tchrist@mox.perl.com>
    Re: Perl "constructors" armchair@my-dejanews.com
    Re: Perl "constructors" armchair@my-dejanews.com
    Re: Perl "constructors" <rra@stanford.edu>
    Re: Perl "constructors" <tchrist@mox.perl.com>
    Re: Perl "constructors" (Sam Holden)
    Re: Perl "constructors" <rra@stanford.edu>
    Re: Perl "constructors" (Sam Holden)
        uninitialized value <xyf@inetnebr.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 15 May 1999 04:04:18 GMT
From: armchair@my-dejanews.com
Subject: Re: Hash arrays
Message-Id: <7hiro2$9nt$1@nnrp1.deja.com>

In article <slrn7jo31p.hn5.sholden@pgrad.cs.usyd.edu.au>,
  sholden@cs.usyd.edu.au wrote:
> On Fri, 14 May 1999 11:17:11 GMT, armchair@my-dejanews.com wrote:
> >How do I find out the number of elements in a hash array?
>
> A hash isn't an array...
>
> $number_elements = keys %hash; #


Thanks. It seems a bit much, as all I really want to do is check to see
if the hash has elements:

$num_elements = entries(%hash);

Do they have a place to post requested enhancements to Perl?
>
> --
> Sam
>
> If your language is flexible and forgiving enough, you can prototype
> your belief system without too many core dumps.
> 	--Larry Wall
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Sat, 15 May 1999 04:02:06 GMT
From: armchair@my-dejanews.com
Subject: Re: Hash arrays
Message-Id: <7hirju$9n4$1@nnrp1.deja.com>

In article <7hh47d$14q$1@nnrp1.deja.com>,
  John Porter <jdporter@min.net> wrote:
> In article <7hh0nm$uqm$1@nnrp1.deja.com>,
>   armchair@my-dejanews.com wrote:
> > How do I find out the number of elements in a hash array?
> > Thanks
>
> perldoc perlfaq4: How can I know how many entries are in a hash?

Can you add a function (a complement to exists() ) that does it? Then I
can read about it in the part of books that talk about associative
arrays, or better yet, in perlfunc.

>
> --
> John Porter
> Put it on a plate, son.  You'll enjoy it more.
>
> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Sat, 15 May 1999 04:04:02 GMT
From: armchair@my-dejanews.com
Subject: Re: Hash arrays
Message-Id: <7hirnh$9no$1@nnrp1.deja.com>

In article <slrn7jo31p.hn5.sholden@pgrad.cs.usyd.edu.au>,
  sholden@cs.usyd.edu.au wrote:
> On Fri, 14 May 1999 11:17:11 GMT, armchair@my-dejanews.com wrote:
> >How do I find out the number of elements in a hash array?
>
> A hash isn't an array...
>
> $number_elements = keys %hash; #


Thanks. It seems a bit much, as all I really want to do is check to see
if the hash has elements:

$num_elements = entries(%hash);

Do they have a place to post enhancements to Perl?
>
> --
> Sam
>
> If your language is flexible and forgiving enough, you can prototype
> your belief system without too many core dumps.
> 	--Larry Wall
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 14 May 1999 22:26:48 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Hash arrays
Message-Id: <373cf788@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    armchair@my-dejanews.com writes:
:if the hash has elements:
:$num_elements = entries(%hash);

READ
THE 
FUCKING
MANUAL
-- 
Unix is like a toll road on which you have to stop every 50 feet to
pay another nickel.  But hey!  You only feel 5 cents poorer each time.
	--Larry Wall in <1992Aug13.192357.15731@netlabs.com>


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

Date: 14 May 1999 22:28:41 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Hash arrays
Message-Id: <373cf7f9@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    armchair@my-dejanews.com writes:
:Thanks. It seems a bit much, as all I really want to do is check to see
:if the hash has elements:
:$num_elements = entries(%hash);
:Do they have a place to post requested enhancements to Perl?

You said that before.  Do you have licence to drive that software,
or are just someone's brat child hitting the send key again and
again?

Here's a nickel kid.  Get yourself a real computer, and a real 
newsreader.  And learn how to use it.  Hint: RTFM.

Sheesh.  

--tom
-- 
 "VAX. For those who care enough to steal the very best."
     -- A microscopic message on the silicon chip inside
	one of Digital Equipment's often stolen computer designs.


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

Date: 15 May 1999 04:51:54 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Hash arrays
Message-Id: <slrn7jpvba.871.sholden@pgrad.cs.usyd.edu.au>

On Sat, 15 May 1999 04:04:02 GMT, armchair@my-dejanews.com wrote:
>In article <slrn7jo31p.hn5.sholden@pgrad.cs.usyd.edu.au>,
>  sholden@cs.usyd.edu.au wrote:
>> On Fri, 14 May 1999 11:17:11 GMT, armchair@my-dejanews.com wrote:
>> >How do I find out the number of elements in a hash array?
>>
>> A hash isn't an array...
>>
>> $number_elements = keys %hash; #
>
>
>Thanks. It seems a bit much, as all I really want to do is check to see
>if the hash has elements:
>
>$num_elements = entries(%hash);

So write it, it;s a one line sub. Of course it will be slower since you'll
actually convert the hash into an array.

Why is it hard to type keys instead of entries. It's shorter even ;).
The documentation says that is how you count the elements in a hash. Just
read keys as entries if you must.

How you could see that as a bit much I fail to understand. It's documented.
It's consistant with the rest of perl. You don't even have to search the docs
for this entries function of yours. You just use the basics of perl.

>
>Do they have a place to post enhancements to Perl?

Hopefully you don't find it.

-- 
Sam

Computers in the future may weigh no more than 1.5 tons.
	--Popular Mechanics, 1949


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

Date: 15 May 1999 04:54:18 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Hash arrays
Message-Id: <slrn7jpvfq.871.sholden@pgrad.cs.usyd.edu.au>

On Sat, 15 May 1999 04:02:06 GMT, armchair@my-dejanews.com wrote:
>In article <7hh47d$14q$1@nnrp1.deja.com>,
>  John Porter <jdporter@min.net> wrote:
>> In article <7hh0nm$uqm$1@nnrp1.deja.com>,
>>   armchair@my-dejanews.com wrote:
>> > How do I find out the number of elements in a hash array?
>> > Thanks
>>
>> perldoc perlfaq4: How can I know how many entries are in a hash?
>
>Can you add a function (a complement to exists() ) that does it? Then I
>can read about it in the part of books that talk about associative
>arrays, or better yet, in perlfunc.

It's in perlfunc you idiot...

=item keys HASH

Returns a list consisting of all the keys of the named hash.  (In a
scalar context, returns the number of keys.)

RTFM. RTFM. RTFM, in fact even better, go and learn python. Your brain is
not large enough to cope with perl.

-- 
Sam

Even if you aren't in doubt, consider the mental welfare of the person
who has to maintain the code after you, and who will probably put parens
in the wrong place.	--Larry Wall


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

Date: Fri, 14 May 1999 20:41:36 -0400
From: Elaine Ashton <elaine@cts.wustl.edu>
Subject: Re: man pages and FAQs: why posted?
Message-Id: <373CC2C0.DB462D67@cts.wustl.edu>

Lee wrote:

> > I'm wondering why all of the man pages and FAQs are being posted here.
> Wouldn't it make more sense to write a short and simple "FAQ 0.0: Where to
> start" that would point newbies to these resources, and post it every day
> or two?

There is already a weekly posting of "Where to find the FAQ" I believe.
Mr. Christiansen has c.l.p.m. on a 2 hour offset feed of Perl
documentation which serves as a public review as well as fodder for
dejanews and other search engines. Think of it as an information IV :)

e.


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

Date: 15 May 1999 04:39:16 GMT
From: rwmip@glink.net.hk (Raymond Ip)
Subject: Parameter pass to PERL
Message-Id: <7hitpk$o2u$1@unix2.glink.net.hk>

If I written a perl script to run it under UNIX environment, and want to
pass some parameter to the perl script. 

How do I check how many parameter pass to the script ?


Best Regards


Raymond Ip


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

Date: 14 May 1999 22:06:34 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl "constructors"
Message-Id: <373cf2ca@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
:future version will not.  If my proposal about calling some
:method (INITIATE?) on
:
:       my Dog $spot;
:
:is supported, then one will be able to
:
:       my number_only $x;
:
:Here I suppose that number_only::INITIATE ties $x, with STORE checking
:that the data which goes there is "numerical" (whatever it means).  

I would urge you to medidate upon yesterday's mailing to p5p.

--tom

Long ago and far away, a wise man once wrote:

    What seems to have been lost over the years [...] is the common
    understanding of what the design center of the language is.
    While it is clear that the original design center as enunciated by
    [its creator] is no longer sufficient to guide the development of
    the language, there has been no discussion of a replacement for that
    design center.  Indeed, it is not at all clear that the current
    community of users is even in agreement about what the language
    ought to be capable of doing and, perhaps more important, what it
    should not attempt to do.

    The lack of a clearly articulated, generally accepted design center
    for the language has resulted in a lack of a set of principles that
    can be used to judge the direction of language change.  The danger
    is that the language will attempt to become something that does
    everything, with the result that it will do nothing well.

    In his book _Wonderful_Life_, Stephen Gould argues that one should
    not confuse biological evolution with progress.  The forces that
    shape the survival of one species over another, Gould points out,
    are far more random than what is required to allow one to claim
    that species for recently evolved are in any way more advanced or
    superior to those from which they evolved.

    Without a clear design center than can be used to determine a notion
    of progress in the evolution of a language, the changes that have
    been made [...] take on many of the aspects of biological evolution.
    The language has been used able to adapt itself to the changing
    environment of the increasing number of users.  But with no goal
    for the language, the evolution of the language can only be seen as
    change, not progress towards that goal.
-- 
If I had only known, I would have been a locksmith.  --Albert Einstein


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

Date: Sat, 15 May 1999 03:58:15 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hircn$9di$1@nnrp1.deja.com>

In article <373c24e3@cs.colorado.edu>,
  tchrist@mox.perl.com (Tom Christiansen) wrote:
>  [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, armchair@my-dejanews.com writes:
> :I think it is a questionable "feature" of Perl that the user can
define
> :any name for an object constructor.
>
> That's only because you have been traumatized in childhood by
restrictive,
> anal-retentive programming languages that hamper the author's ability
> to translate creative inspiration into codified expression.  Please do
> not inflict your own personal mental blindspots on Perl.

Or perhaps I have done something that most Perl programmers have not:
had to modify other people's code. I don't want to inflict anything on
Perl, but I will certainly not be at service this weekend.


>
> :I think this should be changed.
>
> You've clearly not thought about this very much.  First off, you have
> not provided a detailed analysis of the pros and cons of the current
> approach compared with your suggested mutilation.  More importantly,
> at least five years worth of historical precedent laughs in your face.
>
> Here's a constructor:
>
>     $dbh = DBI->connect("dbi:mysql:somedb:server.host.dom:3306",
> 			"username", "password")
>
> And here's another one:
>
>     $sth = $dbh->prepare(<<EO_SELECT)
> 	SELECT name,salary FROM employees WHERE salary > $limit
>     EO_SELECT

I can speak to this: connect() and prepare() should be member functions
and not constructors as a member function can return a status code of
success or various error codes. A constructor cannot. I would assume you
are adding:

if ( $dbh->MadeConnection() )

and

if ( $sth->Prepared() )

in your code?



>
> And here are four more:
>
>     $topwin = MainWindow->new();
>     $frame1 = $topwin->Frame(-relief => "sunken", -bd => 2);
>     $lister = $frame1->Listbox(qw{
> 		-selectmode browse
> 		-font fixed
> 		-width 30
> 		-height 10
> 		-relief sunken
> 		-bd 2
>     });
>     $tscroll = $frame1->Scrollbar(
> 		-command           => ["yview", $lister],
> 	        -orient            => "vertical",
> 	        -activebackground  => "snow4",
>     );
>

I can't figure out what is going on here. I guess you have inheritance.
What is the hierarchy and the constructor for each class? Am I correct
in believing that each class/module only has one subroutine in which
it does a bless?  In any event, you can't get around the fact that
constructors return a blessed reference. It's nice for functions that
can fail, to return error codes. Or perhaps you are printing error
messages and exiting your program when your constructors fail??


> This is Perl.  This is not Java.  This is not C++.  This is not
Python.
> This is not Eiffel.

I notice a bit of C, along with some DBASE III. And probably some Basic
as well.

>
> :And an object should be able to consist of more than just a
reference.
>
> It has been noted that in computer science there few if any problems
that
> cannot be solved by adding another layer of indirection, of
abstraction.
> A reference is merely indirection.  Therefore, it solves all problems.
> You need nothing else.

There is a difference between wants and needs. Certainly anyone who
wants pizza could be told that people can survive on bread alone.


>
> Perl also has eponymous class metaobjects that are not blessed, but
> I shouldn't imagine you've encountered these yet, or would know
> quite what to do with them if you had.

Correct, and correct.

>
> How long have you been using Perl?  It can't be very long.  You just
asked
> how to count the elements in a "hash array".  This clearly indicates
> that you have not even bothered to peruse the standard documentation,
> because 1), you used severely nonstandard terminology, and because 2)
> you would have found the answer to your question.

Short time. Correct. Not true - I have read the standard documentation
and have a couple of books. I should have said "associative array", then
I would have still looked bad, but I would have been correct.

I don't think it is too much to ask for a function, a complement to
"exists" if you will, that tells how many items are in a hash. I seems
silly to have to create an array from a hash, then assign an array to a
scalar (a silly event in itself) to get the number of items in a hash.
How about:
%hash = ();

if (entries($hash) > 0 )
{
  ... process hash
}

which leads to
@array = ();

if ( entries(@array) > 0 )
{
  ... process array
}

>
> You strike me as the sort who upon arriving Paris for the first time,
> and with nary a single French word nor iota of French history at his
own
> command, would immediately counsel the French to abandon their mother
> tongue and start speaking English as God and Queen command.

Fair enough, but they will end up speaking it someday anyway, so in both
cases I may be wrong today, but ultimately right.

>
> Let me repeat myself for the logic-impaired: This is Perl.
> If you want those other languages, you know where to find them.
>
> There surely in Perl resides more potential, more splendor and
richness,
> more room for creativity and expression than are dreamt of in your
> traumatized cyberlinguistic philosophies.
>
> Criticism derived from ignorance shall seldom be well received.
> I believe, sir, that you have some reading to do.

I am reading, but now I am doing it standing up.

>
> --tom
> --
>     The autodecrement is not magical.
>             --Larry Wall in the perl man page
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Sat, 15 May 1999 04:00:03 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hirg3$9fj$1@nnrp1.deja.com>

In article <373C7065.B83251D3@mail.cor.epa.gov>,
  "David L. Cassell" <cassell@mail.cor.epa.gov> wrote:
> armchair@my-dejanews.com wrote:
> >
> > I think it is a questionable "feature" of Perl that the user can
define
> > any name for an object constructor.
>
> I like to name mine 'Fred'.
>
> > I think this should be changed.
>
> Okay, from now on I'll call it 'Barney'.  But Wilma may become
> quite upset about this.  Not to mention poor little Pebbles.
> I think you're being quite heartless about this.
>
> >                                                              And
> > an object should be able to consist of more than just a reference.
>
> Well, it's also a dessert topping.  And a floor wax!

David, I'm just guessing, but I'll just bet no one wants to have to
maintain your code. But you are a laugh riot.

>
> David
> --
> David Cassell, OAO                     cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 14 May 1999 21:16:42 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Perl "constructors"
Message-Id: <ylk8ub6k7p.fsf@windlord.stanford.edu>

armchair <armchair@my-dejanews.com> writes:

> It doesn't??? It's easier to stuff varibles inside of an array and
> remember which is which and access them via subscripts rather than name
> them and access them by name discretely?? Or stuff them in a hash and
> have to use that bulky syntax to get them out?? You're pulling my leg,
> but you almost had me. But there is the lack of a record construct in
> Perl. Surely we see eye to eye about that oversight.

record.field is exactly two fewer characters than $record{field}.  I don't
find this a tremendous hardship.  So no, we don't see eye to eye about
that; I don't consider it an oversight in the slightest.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 14 May 1999 22:24:36 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl "constructors"
Message-Id: <373cf704@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    armchair@my-dejanews.com writes:
:Or perhaps I have done something that most Perl programmers have not:

Oh, please stop flattering yourself and insulting the rest of the
world in the same breath.

:I can speak to this: connect() and prepare() should be member functions
:and not constructors as a member function can return a status code of
:success or various error codes. 

Again, you're deeply confused.  There's no such thing as a member
function in Perl.  We have methods.  That's it.  All else is convention
alone, whether it be class methods, object methods, or constructors.
Those aren't different things.

If you so very badly care to abuse yourself with C++, please get thee
hence and trouble us no more.  If you want to learn perl, drop the
bullshit.

:A constructor cannot. I would assume you
:are adding:
:
:if ( $dbh->MadeConnection() )

Nope.  I'll take an exception if it fails, or I'll check the
return value.

:I can't figure out what is going on here. 

That's hardly my fault.

:Am I correct
:in believing that each class/module only has one subroutine in which
:it does a bless?  

Of course not.  

And for the record, a class is not a module, although often modules
implement classes.

:In any event, you can't get around the fact that
:constructors return a blessed reference. 

Oh, good.  You're wrong again.  I most certainly can.

:It's nice for functions that
:can fail, to return error codes. 

You're revealing your improper education again.  I'm sorry.

:I notice a bit of C, along with some DBASE III. And probably some Basic
:as well.

Really, child, haven't you something else to do than to insult 
what you cannot understand?

:I don't think it is too much to ask for a function, a complement to
:"exists" if you will, that tells how many items are in a hash. 

RTFM.  We have one.  You missed it.

:Fair enough, but they will end up speaking it someday anyway, so in both
:cases I may be wrong today, but ultimately right.

Que la tomes por culo, anglo bigot.

--tom
-- 
 "We stand on the shoulders of giants and kick
 their ears whenever we feel like it."  --Larry Wall


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

Date: 15 May 1999 04:25:14 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl "constructors"
Message-Id: <slrn7jptpa.871.sholden@pgrad.cs.usyd.edu.au>

On Sat, 15 May 1999 03:31:11 GMT, armchair@my-dejanews.com wrote:
>In article <7hh9rs$58m$1@nnrp1.deja.com>,
>  John Porter <jdporter@min.net> wrote:
>> In article <7hh079$ueo$1@nnrp1.deja.com>,
>>   armchair@my-dejanews.com wrote:

>> > And an object should be able to consist of more than just a
>reference.
>>
>> What would that gain you that you don't already have with references?
>> Even if there was more than a reference, how would you get at it?
>> All data structures in Perl -- other than the basic scalar, array,
>> and hash -- are build using references.  Overlaying the class
>> mechanism on this was a natural thing to do and leads to great
>> convenience in programming.  Have you run into some kind of brick
>> wall as a result of objects only being references?
>
>It is much easier to work with discrete variables rather than
>subscripted array variables. I can remember that total_attendees is the
>number of peope who attended the meeting a lot easier than I can
>$rSelf->[10] is.

I'd use $rSelf->{total_attendees}. If you would actually use a reference to
an array like that then you either don't know perl, or you are an
optimisation idiot...

In fact since I'm using a hash not a stupid C++ variable name, I could
get rid of the damn _ if I felt like it and use :

$rSelf->{'total attendees'}

Maybe you should learn some perl or go back to C++.

>I have not run into any brick wall, but having worked
>with C++, I can assure you that having only one reference in an object
>point to it's data (none of which is a struct or true multi-dimensional
>array) does not lead to a great convenience in programming.

A hash is what perl uses for a struct, it does everything a struct does and
then some...

A multi-dimensional array would be $mda[4][3][2][1][0] = 'bill'; How
is that not a 'true multi-dimensional' array?

Maybe you should learn some perl before start to complain about what
it can't do...

-- 
Sam

If your language is flexible and forgiving enough, you can prototype
your belief system without too many core dumps.
	--Larry Wall


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

Date: 14 May 1999 21:21:59 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Perl "constructors"
Message-Id: <ylhfpf6jyw.fsf@windlord.stanford.edu>

armchair <armchair@my-dejanews.com> writes:

> Why don't you just make your case in this forum. I have read those
> documents and did not reach the same conclusion you have. Perl would not
> have to be C++ to have a fixed name for constructors.

No, but it would be a violation of a very core concept in Perl.  Perl is a
libertarian language.  Perl believes in individual responsibility rather
than mandated control.  Perl believes that the programmer is intelligent
and capable of making their own decisions.  Perl believes that if you
create an object with something other than new, you have a good reason for
that.

> And since C++ is used for major projects, whereas Perl is used on more
> "quick and dirty" small projects, I am very surprised that you would
> feel that the Perl way is the right way.

Most projects are small.

> It is much easier to work with discrete variables rather than
> subscripted array variables. I can remember that total_attendees is the
> number of peope who attended the meeting a lot easier than I can
> $rSelf->[10] is.

Straw man.  You're using an array when you have no reason to do so, and
you're using ugly Hungarian notation to intentionally obfuscate your
variable.

$$self{attendees} is not hard to type and is quite clear, as well as
making it explicit that the data that you're accessing is stored inside
the object (rather than being a lexical or package variable or something
else).  C++ on the other hand gives no visual clues at all about such
matters in the actual code, making reading C++ code an exercise in
multiple windows to find all of the hidden gotchas and action at a
distance.

> I have not run into any brick wall, but having worked with C++, I can
> assure you that having only one reference in an object point to it's
> data (none of which is a struct or true multi-dimensional array) does
> not lead to a great convenience in programming.

Having worked with both C++ and Perl, I can assure you that it does.
There, my statement has just as much support as yours does.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 15 May 1999 04:45:55 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl "constructors"
Message-Id: <slrn7jpv03.871.sholden@pgrad.cs.usyd.edu.au>

On Sat, 15 May 1999 03:58:15 GMT, armchair@my-dejanews.com wrote:
>In article <373c24e3@cs.colorado.edu>,
>  tchrist@mox.perl.com (Tom Christiansen) wrote:
>>  [courtesy cc of this posting sent to cited author via email]
>>
>> In comp.lang.perl.misc, armchair@my-dejanews.com writes:
>> :I think it is a questionable "feature" of Perl that the user can
>define
>> :any name for an object constructor.
>>
>> That's only because you have been traumatized in childhood by
>restrictive,
>> anal-retentive programming languages that hamper the author's ability
>> to translate creative inspiration into codified expression.  Please do
>> not inflict your own personal mental blindspots on Perl.
>
>Or perhaps I have done something that most Perl programmers have not:
>had to modify other people's code. I don't want to inflict anything on
>Perl, but I will certainly not be at service this weekend.

Reading the documentation that tells you how to construct objects of the
type your having to use should be easy enough. If it's not documented
then that's hardly perl's fault. Grep for bless and you have your answer.
It't not like it's difficult or anything.

>
>
>>
>> :I think this should be changed.
>>
>> You've clearly not thought about this very much.  First off, you have
>> not provided a detailed analysis of the pros and cons of the current
>> approach compared with your suggested mutilation.  More importantly,
>> at least five years worth of historical precedent laughs in your face.
>>
>> Here's a constructor:
>>
>>     $dbh = DBI->connect("dbi:mysql:somedb:server.host.dom:3306",
>> 			"username", "password")
>>
>> And here's another one:
>>
>>     $sth = $dbh->prepare(<<EO_SELECT)
>> 	SELECT name,salary FROM employees WHERE salary > $limit
>>     EO_SELECT
>
>I can speak to this: connect() and prepare() should be member functions
>and not constructors as a member function can return a status code of
>success or various error codes. A constructor cannot. I would assume you
>are adding:

How can you have a DBI object that is not connected? It doesn't make sense.
Just because you have to do it like that in C++ doesn't mean you have to
in perl...

If the connection failed for some reason you would return undef. C++ doesn't
do that because C++ isn't perl.

A constructor indicates the error with undef. That allows the user to simply
say || die "Unable to connect" or whatever.

As I said before learn some perl before you start commenting on it's problems.
It has some, the one's you see don't exist though, you just don't know the
language.

>
>if ( $dbh->MadeConnection() )
>
>and
>
>if ( $sth->Prepared() )
>
>in your code?

No '|| die' with the constructor. Maybe not die, maybe something less fatal
if it's not a fatal error.

>>
>> And here are four more:
>>
>>     $topwin = MainWindow->new();
>>     $frame1 = $topwin->Frame(-relief => "sunken", -bd => 2);
>>     $lister = $frame1->Listbox(qw{
>> 		-selectmode browse
>> 		-font fixed
>> 		-width 30
>> 		-height 10
>> 		-relief sunken
>> 		-bd 2
>>     });
>>     $tscroll = $frame1->Scrollbar(
>> 		-command           => ["yview", $lister],
>> 	        -orient            => "vertical",
>> 	        -activebackground  => "snow4",
>>     );
>>
>
>I can't figure out what is going on here. I guess you have inheritance.
>What is the hierarchy and the constructor for each class? Am I correct
>in believing that each class/module only has one subroutine in which
>it does a bless?  In any event, you can't get around the fact that
>constructors return a blessed reference. It's nice for functions that
>can fail, to return error codes. Or perhaps you are printing error
>messages and exiting your program when your constructors fail??

Go and read up on Tk. Tk creates objects with parent objects thus those
are constructors that create an object as a child of the object that
constructs them. It's Tk, it's wierd if you haven't seen or used it
before. 

>
>
>> This is Perl.  This is not Java.  This is not C++.  This is not
>Python.
>> This is not Eiffel.
>
>I notice a bit of C, along with some DBASE III. And probably some Basic
>as well.
>
>>
>> :And an object should be able to consist of more than just a
>reference.
>>
>> It has been noted that in computer science there few if any problems
>that
>> cannot be solved by adding another layer of indirection, of
>abstraction.
>> A reference is merely indirection.  Therefore, it solves all problems.
>> You need nothing else.
>
>There is a difference between wants and needs. Certainly anyone who
>wants pizza could be told that people can survive on bread alone.

You have it wrong. A reference can reference any other data structure.
By using something other than a reference you restrict what you can
use. Can I use a single int as an object in C++, no I have to make a struct
like thing which has an int as it's only data member. Can I use a single
scalar as an object in perl, yes just bless a reference to that scalar.

>
>
>>
>> Perl also has eponymous class metaobjects that are not blessed, but
>> I shouldn't imagine you've encountered these yet, or would know
>> quite what to do with them if you had.
>
>Correct, and correct.
>
>>
>> How long have you been using Perl?  It can't be very long.  You just
>asked
>> how to count the elements in a "hash array".  This clearly indicates
>> that you have not even bothered to peruse the standard documentation,
>> because 1), you used severely nonstandard terminology, and because 2)
>> you would have found the answer to your question.
>
>Short time. Correct. Not true - I have read the standard documentation
>and have a couple of books. I should have said "associative array", then
>I would have still looked bad, but I would have been correct.

Only if you like using old outdated terminology...

>
>I don't think it is too much to ask for a function, a complement to
>"exists" if you will, that tells how many items are in a hash. I seems
>silly to have to create an array from a hash, then assign an array to a
>scalar (a silly event in itself) to get the number of items in a hash.

If you don't like context significant stuff (assigning an array to a scalar 
actually doing what you probably want) then run away from perl and use 
some other language. Python is good. It has much more integrated OO. It's
a bit like perl in some respects. Why don't you go and torture python 
instead.

You obviously don't like the way perl does things. The simple solution is
to not use perl. There are some languages I don't like, so I don't use
them.  If your job involves perl and you don't like perl then do yourself
a favour and find a job that doesn't use the things you hate. Your stress
levels, and family will thank you for it.

>How about:
>%hash = ();
>
>if (entries($hash) > 0 )

$hash is completely seperate from %hash. Learn some perl.

>{
>  ... process hash
>}
>
>which leads to
>@array = ();
>
>if ( entries(@array) > 0 )
>{
>  ... process array
>}

Feel free to write that entries() sub if you like. Perl does it a different
way. I guess you'd want a function to tell you if there was an even number
of elements in the hash as well. Since counting them, and then checking if
that is even seems a silly thing to do.

-- 
Sam

testing? What's that? If it compiles, it is good, if it boots up it is
perfect.
	--Linus Torvalds


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

Date: Fri, 14 May 1999 23:43:39 -0500
From: ktb <xyf@inetnebr.com>
Subject: uninitialized value
Message-Id: <373CFB7B.CE6D7C7F@inetnebr.com>

Hi, I'm writing this script to search a database.  It works fine when I
search the first split, "$parts[0]" but if I try to search "$parts[1]" I
get the following errors:

Use of uninitialized value at ./testst line 19, <BottleFile> chunk
11461.
Use of uninitialized value at ./testst line 19, <BottleFile> chunk
11461.
COOLEY'S/34 NEWBURY ST./BOSTON. Fike 1987:159

The error messages seem to occur on lines not containing the word
searched for, in this case, "fike."  I don't understand what the error
is exactly or how to correct this.  If anyone can help I would
appreciate it.  I've included the script below.
Thanks,
kent  
---------------------------------------------------------------------------------
#!/usr/bin/perl -w

print "Enter string to search: ";
$SearchString = <STDIN>;
chomp($SearchString);
$SearchString =~ tr/a-z/A-Z/;


open(BottleFile, "botglass.txt");
@bottle = <BottleFile>;
    foreach $line (@bottle) {  
        @parts = split(/\t/, $line ); 
        $PartsFile = $parts[1];
        
          } continue {  

        foreach ($PartsFile) {
            if (/\Q$SearchString/i) {
                print join("\t", @parts, "\n"); 
	      }
	  }
      }
--------------------------------------------------------------------------------


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5668
**************************************

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