[12094] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5694 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 17 07:08:03 1999

Date: Mon, 17 May 99 04:01:26 -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           Mon, 17 May 1999     Volume: 8 Number: 5694

Today's topics:
    Re: Perl "constructors" (Alan Curry)
    Re: Perl "constructors" armchair@my-dejanews.com
    Re: Perl "constructors" armchair@my-dejanews.com
        Perl and Oracle <t.klinger@mobilkom.at>
        Perl/CGI or Java Servlets? <tszeto@mindspring.com>
    Re: Sorting of array of hashes. (Michel Dalle)
        Sorting problem <t.klinger@mobilkom.at>
    Re: Strange file reading problem armchair@my-dejanews.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 17 May 1999 07:20:14 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Perl "constructors"
Message-Id: <OqP%2.243$G3.3541@news14.ispnews.com>

In article <yl7lq8xkt4.fsf@windlord.stanford.edu>,
Russ Allbery  <rra@stanford.edu> wrote:
>
>From what I can tell from the documentation, which I agree is very sparse,
>if you set $^M to be a large enough buffer that Perl can survive on it, an
>operation that causes your program to run out of memory will throw an
>exception just as if you'd called die().  You can catch that exception
>with eval {} and do what you want with it.

OK, so the whole program goes in a big eval to make it safe. But what
specifically do you look for in $@ to know this has happened? and when it
does happen, is there a way I can jump back to the same place in the eval
block where it was broken?

Safe malloc'ing in C is a matter of 8 lines:
void *xmalloc(size_t sz)
{
  void *ret;
  while(!(ret=malloc(sz)))
    sleep(1);
  return ret;
}
#define malloc xmalloc

Can perl do that?

>
>I'm sure someone will correct me if I'm reading the documentation wrong.
>Hopefully someone will also clarify the documentation.  :)
>
>I think you may also have to compile Perl with a particular option flag in
>order to get this behavior.

Yes... maybe it is easier to LD_PRELOAD brk and mmap.

-- 
Alan Curry    |Declaration of   | _../\. ./\.._     ____.    ____.
pacman@cqc.com|bigotries (should| [    | |    ]    /    _>  /    _>
--------------+save some time): |  \__/   \__/     \___:    \___:
 Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman


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

Date: Mon, 17 May 1999 10:20:15 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hoqgu$6h8$1@nnrp1.deja.com>

In article <37cfb034.2609401360@news1.newscene.com>,
  aray@interactrx.com wrote:
> In <7ho7bj$pkj$1@nnrp1.deja.com>, armchair@my-dejanews.com wrote:
> | In article <yl675szafm.fsf@windlord.stanford.edu>,
> |   Russ Allbery <rra@stanford.edu> wrote:
> | > armchair <armchair@my-dejanews.com> writes:

> | This has to be a semantical disagreement.
>
> Possibly. "What is an object?"
>
> For Perl, the perlobj page says quite categorically:
>
>        1.  An object is simply a reference that happens to know
>            which class it belongs to.
>
> This is quite distinct from the C++-ish view that an object is an
> instantiation of a class definition (in turn a C-struct on steroids.)

Doesn't Bjarne Stroustrup refer to a C++ object as simply a struct that
happens to know which class it belongs to? ;) I don't see why you feel you
can leave off the fact that a Perl object is also the instantiation of a
package/module definition (in turn a reference on steroids).

>
> | I have ONE reference pointing to ONE data type.
>
> A *Perl* data type: scalar, array, hash, etc.
>
> | My reference can't point to two data types,
>
> It doesn't need to, when it can point to something which can contain
> as many "data types" as you please. (And, as it happens, there's a cat
> lurking in the bag here. It's called 'typeglob'.)

This didn't start from a need, but from a want. This has nothing to do with
"hitting the wall". It is more a dogmatic discussion.

>
> | At the highest level of an object, there is only ONE thing. If you
> | want to say the object is the reference, not that an object contains
> | a reference, then "inside", the object/reference we only have one
> | thing - the singular data type that the reference refers to (or
> | maybe it would be the address of the datatype).
>
> It really sounds like you're asking why Perl doesn't have a direct
> *syntactic* congruent of structs. It doesn't need them.

what do you call the thing on the left below

my ($field1, $field2, $field3, $field4) = unpack("i5",$my_data);

Looks like an anonymous record, no? An unnamed parallel agregation of named
fields. Not that much different from a named one. And what about when I write
it so:

my #record
(
   $field1,
   $field2,
   $field3,
   $field4
)
                = unpack("i5",$my_data);


or:

my #time_record
(
   $seconds,
   $minutes,
   $hours,
   $monthday,
   $month,
   $year,
   $weekday,
   $yearday,
   $isdst
)
               = localtime(time);

And with no records, shouldn't localtime() actually fill what has been
referred to as Perl's record - a hash?



>
> I think your use of "member data" indicates your (futile) search for a
> struct, as only a struct can satisfy your preconception of "object".
> Perl has aggregate "data types" such as arrays, hashes, and typeglobs.
> Most objects are indeed one of these types "at the top level", simply
> because that's all you need to script at Perl's level of abstraction.
> Looking for a linear collection of named ints and chars and floats and
> the like ('member data') is simply Not Getting It.

Before Perl had objects, was the doctrine that you don't need them, and that
anyone suggesting as much was simply Not Getting It? Or more generally, has
their ever been a time when a feature was asked for in Perl, and the doctrine
was against it, and it was later added to the language?


>
> | then the top level of what an object contains is one thing - whatever
> | data structure the reference refers to.
>
> Yes, replacing "contains" with "consists of". What exactly is the
> difficulty with that?

You are late to the discussion but it revolved around my requesting that an
object hold more than one item, or as you would have it - I was on a futile
search for a struct. And then it was said that Perl objects do not just
contain one item. And so it went and goes...


> | > You cannot create a blessed array in C++, for example. You can
> | > create an object with a bunch of overloaded operators that mostly,
> | > but not entirely, acts like an array except for the stuff that
> | > you forgot, but that's not the same thing.
> |
> | In Perl a "blessed array" would be an object that contains/is a
> | reference to an array, correct?
>
> Correct. That array can subsequently be manipulated as just an array
> if you like: that is, all operations which make sense for an array are
> still possible regardless of the "objectness".

It still has to be dereferenced, before it can be manipulated as an array. And
arrays inside C classes/structs can be manipulated as an external array, once
it is "derefererenced" by adding the objectname. to the array name.

>
> | Why do you think that a C++ object cannot contain an array as it's
> | member data?
>
> It can, but you can't use the object *syntactically* as you would or
> could any garden-variety array, without also defining a whole bunch of
> operator overloadings. That was Russ' point.

I disagree. Just as you have to dereference the Perl object to get at the
array, as I wrote previously: push(@$my_object,1); you also can do anything
with the array inside a C++ object once you "dereference it".
push(my_object.array,1);

>
> | The C++ object is the reference
>
> To a *struct*, not an array. In C++, objects are structs necessarily,
> because that is the only "top level" mechanism available to aggregate
> 'member data'.

I don't see how the C++ object name is any less a reference to the array it
contains, than a Perl object name is a reference to the array it "contains".

>
> | and the array is what it contains, the data it refers to. I don't see
> | why you think it's different.
>
> Because there's no struct-like data structure intervening, as there is
> in C++.

Here's perl  @$my_object
Here's C++   my_object.array

You could equate the . and the @ and you are left with one has a field name
in addition to the object name. So there is the addition of a field name to
get at an underlying data structure, agreed. I guess Perl's the lack therof
could be toutable - to some degree. But both names above can be used
identically. Having the C++ object "reference a struct" has not precluded
identical usage (i.e. usaged in statements as if it was the same type of data
structure external to the class). But in cases where we are protecting the
underlying data as we are supposed to - having object methods manipulate its
data or state -  not passing our internal to data for external functions to
manipulate, it ends up being identical and any "having to name the field in
the struct" advantage disappears:

$my_object->GetStatesArray();
my_object.GetStatesArray();
$my_object->SetStatesArray(input);
my_object.SetStatesArray(input);



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


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

Date: Mon, 17 May 1999 10:20:10 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hoqgp$6h6$1@nnrp1.deja.com>

In article <37cfb034.2609401360@news1.newscene.com>,
  aray@interactrx.com wrote:
> In <7ho7bj$pkj$1@nnrp1.deja.com>, armchair@my-dejanews.com wrote:
> | In article <yl675szafm.fsf@windlord.stanford.edu>,
> |   Russ Allbery <rra@stanford.edu> wrote:
> | > armchair <armchair@my-dejanews.com> writes:

> | This has to be a semantical disagreement.
>
> Possibly. "What is an object?"
>
> For Perl, the perlobj page says quite categorically:
>
>        1.  An object is simply a reference that happens to know
>            which class it belongs to.
>
> This is quite distinct from the C++-ish view that an object is an
> instantiation of a class definition (in turn a C-struct on steroids.)

Doesn't Bjarne Stroustrup refer to a C++ object as simply a struct that
happens to know which class it belongs to? ;) I don't see why you feel you
can leave off the fact that a Perl object is also the instantiation of a
package/module definition (in turn a reference on steroids).

>
> | I have ONE reference pointing to ONE data type.
>
> A *Perl* data type: scalar, array, hash, etc.
>
> | My reference can't point to two data types,
>
> It doesn't need to, when it can point to something which can contain
> as many "data types" as you please. (And, as it happens, there's a cat
> lurking in the bag here. It's called 'typeglob'.)

This didn't start from a need, but from a want. This has nothing to do with
"hitting the wall". It is more a dogmatic discussion.

>
> | At the highest level of an object, there is only ONE thing. If you
> | want to say the object is the reference, not that an object contains
> | a reference, then "inside", the object/reference we only have one
> | thing - the singular data type that the reference refers to (or
> | maybe it would be the address of the datatype).
>
> It really sounds like you're asking why Perl doesn't have a direct
> *syntactic* congruent of structs. It doesn't need them.

what do you call the thing on the left below

my ($field1, $field2, $field3, $field4) = unpack("i5",$my_data);

Looks like an anonymous record, no? An unnamed parallel agregation of named
fields. Not that much different from a named one. And what about when I write
it so:

my #record
(
   $field1,
   $field2,
   $field3,
   $field4
)
                = unpack("i5",$my_data);


or:

my #time_record
(
   $seconds,
   $minutes,
   $hours,
   $monthday,
   $month,
   $year,
   $weekday,
   $yearday,
   $isdst
)
               = localtime(time);

And with no records, shouldn't localtime() actually fill what has been
referred to as Perl's record - a hash?



>
> I think your use of "member data" indicates your (futile) search for a
> struct, as only a struct can satisfy your preconception of "object".
> Perl has aggregate "data types" such as arrays, hashes, and typeglobs.
> Most objects are indeed one of these types "at the top level", simply
> because that's all you need to script at Perl's level of abstraction.
> Looking for a linear collection of named ints and chars and floats and
> the like ('member data') is simply Not Getting It.

Before Perl had objects, was the doctrine that you don't need them, and that
anyone suggesting as much was simply Not Getting It? Or more generally, has
their ever been a time when a feature was asked for in Perl, and the doctrine
was against it, and it was later added to the language?


>
> | then the top level of what an object contains is one thing - whatever
> | data structure the reference refers to.
>
> Yes, replacing "contains" with "consists of". What exactly is the
> difficulty with that?

You are late to the discussion but it revolved around my requesting that an
object hold more than one item, or as you would have it - I was on a futile
search for a struct. And then it was said that Perl objects do not just
contain one item. And so it went and goes...


> | > You cannot create a blessed array in C++, for example. You can
> | > create an object with a bunch of overloaded operators that mostly,
> | > but not entirely, acts like an array except for the stuff that
> | > you forgot, but that's not the same thing.
> |
> | In Perl a "blessed array" would be an object that contains/is a
> | reference to an array, correct?
>
> Correct. That array can subsequently be manipulated as just an array
> if you like: that is, all operations which make sense for an array are
> still possible regardless of the "objectness".

It still has to be dereferenced, before it can be manipulated as an array. And
arrays inside C classes/structs can be manipulated as an external array, once
it is "derefererenced" by adding the objectname. to the array name.

>
> | Why do you think that a C++ object cannot contain an array as it's
> | member data?
>
> It can, but you can't use the object *syntactically* as you would or
> could any garden-variety array, without also defining a whole bunch of
> operator overloadings. That was Russ' point.

I disagree. Just as you have to dereference the Perl object to get at the
array, as I wrote previously: push(@$my_object,1); you also can do anything
with the array inside a C++ object once you "dereference it".
push(my_object.array,1);

>
> | The C++ object is the reference
>
> To a *struct*, not an array. In C++, objects are structs necessarily,
> because that is the only "top level" mechanism available to aggregate
> 'member data'.

I don't see how the C++ object name is any less a reference to the array it
contains, than a Perl object name is a reference to the array it "contains".

>
> | and the array is what it contains, the data it refers to. I don't see
> | why you think it's different.
>
> Because there's no struct-like data structure intervening, as there is
> in C++.

Here's perl  @$my_object
Here's C++   my_object.array

You could equate the . and the @ and you are left with one has a field name
in addition to the object name. So there is the addition of a field name to
get at an underlying data structure, agreed. I guess Perl's the lack therof
could be toutable - to some degree. But both names above can be used
identically. Having the C++ object "reference a struct" has not precluded
identical usage (i.e. usaged in statements as if it was the same type of data
structure external to the class). But in cases where we are protecting the
underlying data as we are supposed to - having object methods manipulate its
data or state -  not passing our internal to data for external functions to
manipulate, it ends up being identical and any "having to name the field in
the struct advantage" disappears:

$my_object->GetStatesArray();
my_object.GetStatesArray();
$my_object->SetStatesArray(input);
my_object.SetStatesArray(input);



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


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

Date: Mon, 17 May 1999 09:34:45 +0200
From: "Thomas Klinger" <t.klinger@mobilkom.at>
Subject: Perl and Oracle
Message-Id: <7hogqn$8ni$1@fleetstreet.Austria.EU.net>

Hi there!

Maybe this might be a simple question but because I'm a bit new to PERL I
cannot answer myself.

I have a system on HPUX 10.20, clustered with MC/SG, with a comm-, a db- and
a spare-package.
Additional I use a Linux system with an Apache-webserver.
Those 2 systems are connected within a large TCP/IP net.

What I want to do is doing some SQL-queries from a CGIscript on my Linuxbox
on the db-package(btw, the db-package is an ORACLE database, version 7.3.2).
I know that I have an installed DBI package and a DBD:Oracle package.
But how do I have to work with? How does the connection string is looking
like?
What environment have I to build that my project would work exactly?

Every message is welcome. Please excuse my sometimes worse English.

--
Best regards,
                  Thomas Klinger
========================================
 ......E-Mail: t.klinger@mobilkom.at.....
 .........WWW: http://www.mobilkom.at....
========================================




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

Date: Mon, 17 May 1999 00:43:15 -0700
From: "ted" <tszeto@mindspring.com>
Subject: Perl/CGI or Java Servlets?
Message-Id: <7hohad$ues$1@nntp9.atl.mindspring.net>

Are their any major advantages in using Java Servlets instead of Perl/CGIs?

If one uses mod_perl, is the speed issue moot?

-Ted




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

Date: Mon, 17 May 1999 09:52:00 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Sorting of array of hashes.
Message-Id: <7hooqi$om5$1@news.mch.sbs.de>

In article <MPG.11a920059c710d9d9896cf@news>, design@raincloud-studios.com (Charles R. Thompson) wrote:
>In article <7hne02$em8$1@xenon.inbe.net>, Michel Dalle says...
>> In article <MPG.11a8eed9283edc1d9896cd@news>, design@raincloud-studios.com
> (Charles R. Thompson) wrote:
>
>> Would the following be too 'simple' ?
>
>Simple.. complex.. I don't care either way... as long as I learn how. :) 
>This works... of course it went right by me, but I'll look at it real 
>close because I must be missing the obvious. :) Thanks so much.

I think you were concentrating too much on using (@pages), which returns
each element in the array, i.e. a hash in each loop. To be honest, I wasn't 
too sure on how to use $a and $b for sorting in this context either :-)
See below.

>The only drawback is having to add a 'manual' counter to display page 
>numbers in the loop. With the Foreach loop in your example, it returns 
>the position of the sorted page in the original array. So number wise, 
>things are out of whack. No biggie though. There's no way you could have 
>known that without a code example.

Well, this was just an example. Obviously the page numbers are in 'sorted'
order in this case, but you may not need them anyway.

So here is how you could do your sort without the intermediate page numbers :

for (sort {$a->{'title'} cmp $b->{'title'}} @pages) {
        print "$_->{'title'} - $_->{'etc..'}\n";
}

I'm sure you can do it with 'map' too, but this feels more 'comprehensible' 
for non-Perl experts like me. :-)

>> foreach $page (sort by_title 0..$#pages) {
>>         &printpage($page);
>> }
>
>I haven't figured this out yet, but for some reason I keep ending up with 
>a blank record at element 0 in my array. It's been there from the 
>start. Starting the loop at 1 fixes it, but I still haven't tracked down 
>where the 'ghost record' comes in.

That depends on how you fill in your array at the start. Or did you change
the $[ variable somewhere to start arrays at 1 rather than 0 ?

Happy hunting,

Michel.

--
aWebVisit - extracts visitor information from WWW logfiles and shows
the top entry, transit, exit and 'hit&run' pages, the links followed
inside your website, the time spent per page, the visit duration etc.
For more details, see http://gallery.uunet.be/Michel.Dalle/awv.html


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

Date: Mon, 17 May 1999 11:05:13 +0200
From: "Thomas Klinger" <t.klinger@mobilkom.at>
Subject: Sorting problem
Message-Id: <7hom4b$g9g$1@fleetstreet.Austria.EU.net>

Hi there, again me! :)

I've written this code:

[...]
foreach $techline (@techlines) {
  ($type, $setnr, $technr, $subject, $s5, $s6, $s7, $note) = split (/;/,
$techline);
  chop ($note) if $note =~ /\n$/;
  $s5 =~ s/^/\-/ if $s5 eq "";
  $s6 =~ s/^/\-/ if $s6 eq "";
  $s7 =~ s/^/\-/ if $s7 eq "";
  if ($setnr =~ m/$FORM{'TNSET'}/i){
   print
"<tr><td>$type</td><td>$setnr</td><td>$technr</td><td>$subject</td><td>$s5</
td><td>$s6</td><td>$s7</td><td>$note</td></tr>\n";
  }
 }
[...]

The problem: in variable $technr are numbers in miscellaneues order. How do
I have to change the code that the results are ordered by their value
$technr descending?
Should I push the values into an array/hash then do a sort? That would mean
that I'm doing the job twice (split, looking for match, push, sort, split).
Is there an easier way?

Thanx to all in forward for the help.

--
Best regards,
                  Thomas Klinger
========================================
 ......E-Mail: t.klinger@mobilkom.at.....
 .........WWW: http://www.mobilkom.at....
========================================




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

Date: Mon, 17 May 1999 10:36:23 GMT
From: armchair@my-dejanews.com
Subject: Re: Strange file reading problem
Message-Id: <7horf7$773$1@nnrp1.deja.com>

In article <373F968B.7E9@uic.edu>,
  David Lent <dlent1@uic.edu> wrote:
> I'm using the -w but it's not giving any info. about this problem.  I've
noticed something even stranger now.
>  If I use:
> $var=<NEWFILE>;
> print "$var";
>
> it prints the First part of the file.
>
> If I use:
> print <NEWFILE>;
> it prints the Second part of the file.  This is one of the strangest things
> I've ever seen.

What happens when you replace print <NEWFILE> / $var=<NEWFILE>;
print "$var";   with:

my $line;
while ( $line = <NEWFILE> )
{
   print "--> $line";
}



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


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

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

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