[10147] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3740 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 17 12:07:13 1998

Date: Thu, 17 Sep 98 09:01:29 -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           Thu, 17 Sep 1998     Volume: 8 Number: 3740

Today's topics:
    Re: Perl & Java - differences and uses <garry@sage.att.com>
    Re: Perl & Java - differences and uses <arcege@shore.net>
    Re: Perl & Java - differences and uses <zenin@bawdycaste.org>
        Q:Non-blocking system read - how to cancel block but no <Cosmas.Lang@Uni-Mainz.DE>
        Redirecting STDERR to file then back to terminal? <tturton@cowboys.anet-dfw.com>
    Re: Style question re ($k => $v) (Abigail)
    Re: Style question re ($k => $v) (Abigail)
    Re: trying to use print<<END; with CGI.pm <jdw@dev.tivoli.com>
    Re: What is Perl related? [was Re: how safe is xor encr <eashton@bbnplanet.com>
    Re: Who posts original posts on CLPM? <eashton@bbnplanet.com>
        win32:ODBC/Oracle->terrible perormance ka0osk@creighton.edu
    Re: Y2K date in Perl <sneaker@sneex.fccj.org>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 17 Sep 1998 09:51:39 -0400
From: "Garrett G. Hodgson" <garry@sage.att.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <360113EB.16CD2A2D@sage.att.com>

Zenin wrote:
>         In a language that relies entirely on magic whitespace for block
>         roles, isn't a 2 space indent a really bad idea, readability and
>         maintainance wise?

the "magic whitespace" rant is getting tiresome.
in practice, i find it just isn't an issue.  2 spaces,
4 spaces, tabs, whatever.  a consistent indentation is
what you want to aid comprehension, and is also what python
wants to determine structure.  works out rather well.
looking at your own code examples, which are nicely laid out,
the curly braces add nothing to comprehension but visual noise.

for years people have been arguing about where to put the curly 
braces in c/c++.  python eliminated that argument, and so had to
find some other style religious argument to have.  thus the 
periodic flare-ups in comp.lang.python over indentation styles.

-- 
Garry Hodgson			and when they offer
garry@sage.att.com		golden apples
Software Innovation Services	are you sure you'll refuse?
AT&T Labs			heaven help the fool.


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

Date: Thu, 17 Sep 1998 15:29:47 GMT
From: "Michael P. Reilly" <arcege@shore.net>
Subject: Re: Perl & Java - differences and uses
Message-Id: <LV9M1.96$_c5.935794@news.shore.net>

In comp.lang.python Andrew Dalke <dalke@bioreason.com> wrote:
:> : For example, you cannot make a list of regular expressions.
:> 
:>         Sure you can, even in perl 4.  They are only strings after
:>         all.
:> 
:>         my @list_o_patterns = qw(this that dog (?i)insensitive);
:> 
:>         foreach my $pat (@list_o_patterns) {
:>             something() if ($string =~ /$pat/);
:>         }

What version of Perl4 had "qw"? ;)

: True, and I've been smacking myself on the head forgetting that. 
: But it isn't the same since it recompiles the pattern every time
: it is used. (Wait, I seem to remember something about if a string
: is used as an re, then the compiled pattern is stored until the
: string changes, In that way, if the string is used as a pattern again
: it doesn't need to recompile.  Don't know if it's true, but it
: could happen.)

With Perl 5.004_04 and earlier, compiled REs won't work.  Compiling the
pattern prevents interpolation, this means that the same pattern is
used through out the loop.

sub tryit {
  local ($value, @patts) = @_;
  local ($pat);
  for $pat (@patts) {
    @vals = $value =~ /$pat/o;
    print "$value =~ /$pat/ => (@vals)\n";
  }
}

@patts = ('(\w+)\s+(\w+)', '(\d{5})(-\d{4})?');
$name = 'Michael P. Reilly';
$zipcode = '01234-1212';
&tryit($name, @patts);
&tryit($zipcode, @patts);

And you get:
Michael P. Reilly =~ /(\w+)\s+(\w+)/ => (Michael P)
Michael P. Reilly =~ /(\d{5})(-\d{4})?/ => (Michael P)
01970-5212 =~ /(\w+)\s+(\w+)/ => ()
01970-5212 =~ /(\d{5})(-\d{4})?/ => ()
(No, there are no dependancies on the function or the scoping.)  Works
well, eh?


"And now for something completely different..."

:> In a language that relies entirely on magic whitespace for block
:> roles, isn't a 2 space indent a really bad idea, readability and
:> maintainance wise?

It's been advocated for well more than 20 years that proper indentation
in code is a requirement for "good readability and maintenance".  Here
"proper indentation" means that you indent block and keep the same
indentation throughout that block.  Python just inforces this.  And it
isn't a two space policy,  it is a "all statements within the block
must have the same indentation" policy.  A good many of python
programmers use four spaces, where I use two myself (the same with my
C code, and Perl when I used to write it).

As a release manager, I find Python to be much more desirable as a
product-based programming language (as a programmer I find that it's
far more logical than Perl5).

Now, in a language that allows many different, often cryptic tricks and
methods of doing the same thing, maintainability and readability
becomes an issue.

:> Does Python really need the archaic "count = count + 1"?

It's archaic to people who think auto-increment is a good idea; auto-
increment and auto-decrement are just syntax sugar and Python has tried
not to bring syntax sugar into the language - why complicate the
language if you don't need to?  The second reason Python uses this
syntax is because all attributes (ie. variables) are references to
objects.  "count++" is the same as "count+=1", which leads to a good
deal of semantic confusion when you get into a something like:
  a = [1, 2, 3]
  a++

Does this result in [1, 2, 3, None] or [2, 3, 4] (there is already an
operation [1, 2] * 2 == [1, 2, 1, 2], hence the first result)?  Then
there is the more conflicting:
  "Hi"++

where strings are immutable in Python (unlike Perl, and for good
reason).  Do you return a new string and lose the reference to the
existing string?

There is already a hot debate about adding "<op>=" operators on
comp.lang.python, so I'm not going to rehash it.  I'll just say that a
good deal of Python attractiveness is that the core language is
consistant and simple (not something you can say about Perl5).

	Arcege

PS: I'm not sure why this is on comp.lang.java.programmer anymore,
so I've removed it from the cross-postings.



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

Date: 17 Sep 98 15:41:48 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <906047183.589733@thrush.omix.com>

Garrett G. Hodgson <garry@sage.att.com> wrote:
	>snip<
: the "magic whitespace" rant is getting tiresome.

	Maybe, but it's also quite valid.

: in practice, i find it just isn't an issue. 2 spaces,
: 4 spaces, tabs, whatever.  a consistent indentation is
: what you want to aid comprehension, and is also what python
: wants to determine structure.  works out rather well.

	The problem is when tabs and spaces are used together, at
	which point the design fails hard.

: looking at your own code examples, which are nicely laid out,

	<blush>

: the curly braces add nothing to comprehension but visual noise.

	Stretch a block over a screen boundary (such as for a package/class
	def) and they add quite a bit.  They also make it very easy to jump
	to the ends of a given block, which in the case of the above could
	be many screens away.  They also add freedom in coding style, which
	is considered a feature by nearly every language except Python.

: for years people have been arguing about where to put the curly 
: braces in c/c++.

	Quite true, but only because many people are wrong. :-)

: python eliminated that argument, and so had to find some other
: style religious argument to have.

	It replaced a purely style issue with a real problem.  I
	fail to see how this would be a good thing.

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Thu, 17 Sep 1998 16:30:55 +0200
From: Cosmas Lang <Cosmas.Lang@Uni-Mainz.DE>
Subject: Q:Non-blocking system read - how to cancel block but not program?
Message-Id: <36011D1F.6D372902@Uni-Mainz.DE>

I've got the following problem (perl5.004):
My perl program tests several tcp servers in well defined time
intervalls by sending a request and then reading some bytes from them.
Now in some rare cases the select returns, but the sysread blocks, so I
have to cancel the read.
But
 
	  READ: {
	      local $SIG{'ALRM'} = sub { $timed_out = 1; };
	      alarm $timeout;          # prevent blocking of sysread()

	      if ($req_length > 0 && !$timed_out) {
		  syswrite (SOCK, $request, $req_length);      # send request
	      }
	      sysread  (SOCK, $buffer, 400) unless $timed_out; # read answer
	  } # End READ
	    $time_left = alarm(0);

doesn't solve the problem, because the sub returns right back into the
sysread.
Either does a
  sub { last READ; }
because it's not possible to jump from one subroutine to a label in
another one.
I think in perl5.003 that was allowed, even with a 'goto', but I want to
have it run in 5.004 now.

Any suggestions how I can tell perl to cancel the sysread WITHOUT having
to put it in a fork and kill that?
---------
Cosmas Lang  (Cosmas.Lang@Uni-Mainz.DE)


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

Date: Thu, 17 Sep 1998 10:42:12 -0500
From: Tom Turton <tturton@cowboys.anet-dfw.com>
Subject: Redirecting STDERR to file then back to terminal?
Message-Id: <36012DD4.988D4D30@cowboys.anet-dfw.com>

If I want to temporarily redirect standard error messages to a file,
then later direct it back to the screen again, is it as simple as this
(which appears to work):

open (STDERR, ">temp_err.log");

   (first batch of error messages go to temp_err.log)

open (STDERR, ">-");

   (second batch of error message return to being output to screen)


Originally I tried closing STDERR in between the two "opens", but that
resulted in the second batch of error messages just being lost (neither
in temp_err.log or on screen).

It just seems wrong to do the second open on STDERR without first
closing it, or am I fretting about nothing?

Thanks,

---Tom Turton



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

Date: 17 Sep 1998 15:25:22 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Style question re ($k => $v)
Message-Id: <6tr9l2$fub$3@client3.news.psi.net>

Larry Rosler (lr@hpl.hp.com) wrote on MDCCCXLIII September MCMXCIII in
<URL: news:MPG.106a68a1b6eb6084989861@nntp.hpl.hp.com>:
++ In article <6tq2b5$2r0$3@client3.news.psi.net> on 17 Sep 1998 04:14:29 
++ GMT, Abigail <abigail@fnx.com> says...
++ > Mark-Jason Dominus (mjd@op.net) wrote on MDCCCXLIII September MCMXCIII in
++ > <URL: news:6tprqp$8ob$1@monet.op.net>:
++ ...
++ > ++ Lately I've found myself writing
++ > ++ 
++ > ++ 	while (($k => $v) = each %h) {
++ > ++ 	  ...
++ > ++ 	}
++ > ++ 
++ > ++ Does anyone have any comments about this?
++ ...
++ >      split /regex/ => $string;
++ >      join  "" => @list;
++ >      %hash = map {$_ => 1} @list;
++ >      sprintf "format" => $arg1, $arg2, $arg3;
++ 
++ > I tend to use it in cases where the first argument of a function
++ > has a very different role than the others. => makes a bigger
++ > visual impact than a , tucked against the operand.
++ 
++ I use all of those, for that reason.  In addition, these follow the same 
++ model as 'join' and 'sprintf':
++ 
++    grep EXPR => LIST
++    map  EXPR => LIST

Yes, but I always use the grep {BLOCK} LIST, and map {BLOCK} LIST forms,
but would I use the EXPR forms, I probably would use => as well.

++ One way of reading this '=>' is 'applied to' ...
++ 
++ And, finally,
++ 
++    rename NAME1 => NAME2

That's a nice one!

++    utime EXPR, EXPR => NAME


I also use:

      use contant FOO => 1;



Does anyone use

      EXPR => EXPR => EXPR

?



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: 17 Sep 1998 15:28:41 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Style question re ($k => $v)
Message-Id: <6tr9r9$fub$4@client3.news.psi.net>

Rick Delaney (rick.delaney@shaw.wave.ca) wrote on MDCCCXLIII September
MCMXCIII in <URL: news:3601039A.76C2258A@shaw.wave.ca>:
++ Abigail wrote:
++ > 
++ > While I wouldn't use while (($k => $v) = each %h), I often do
++ > things like:
++ [snip]
++ > 
++ >       %hash = map {$_ => 1} @list;
++ 
++ These seem very similar to me.  Is there a reason why you would do one
++ and not the other?

Yes. ($k, $v) is a list, but %hash is a hash.

I would not write:
           @list = map {$_ => 1} @list2;

but
           @list = map {($_, 1)} @list2;



Abigail
-- 
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-


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

Date: 16 Sep 1998 22:54:24 -0500
From: "Jim Woodgate" <jdw@dev.tivoli.com>
Subject: Re: trying to use print<<END; with CGI.pm
Message-Id: <obiuins8b3.fsf@alder.dev.tivoli.com>


Al Smith <alanson@umich.edu> writes:
> it's not working and i can't find any examples anywhere:
> Lincoln's
> metronet
> Perllang
> CPAN

always works for me, maybe you could post some code that isn't working
and people can take a look at it...

-- 
Jim Woodgate 
Tivoli Systems
E-Mail: jdw@dev.tivoli.com


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

Date: Thu, 17 Sep 1998 15:32:01 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: What is Perl related? [was Re: how safe is xor encryption ?]
Message-Id: <3601290D.D94D6D84@bbnplanet.com>

Ronald J Kimball wrote:

> Why do people have such a broad idea of 'what is Perl related'.  This
> was started by someone who wanted to do an e-commerce solution,
> coincidentally in Perl.  And the discussion has continued to have
> nothing whatsoever to do with Perl.

Take my point. Perl is not an entity living in a vacuum independent of
anything else. Yes, it did start out as a Perl question on e-commerce
but digressed into a discussion on security and encryption. Perhaps you
are uninterested in anything along those lines, but since Perl people in
my general experience tend to be 'jack of all trade' type of people, it
was somewhat a linear progression of the topic. 

Security is an important point whether you're dealing with Perl or
something else. And certainly it was a much more interesting discourse
than 'hey, why doesn't this 3 line perl program work?'. It's only Usenet

e.

"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon."  R. Carver


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

Date: Thu, 17 Sep 1998 15:23:28 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Who posts original posts on CLPM?
Message-Id: <3601270B.3B18DDEB@bbnplanet.com>

Andrew Johnson wrote:

> yes, there are all kinds of lies, and statistics are often one kind
> (or worse, an argument for another lie) ... nevertheless, frequency
> data (ratios) counts (as a statistic) ... which is why there are all
> kinds of statistical methods to test differences in frequency data
> (ie: similar to simple averages, an average is "a statistic" ... but
> by itself what does it denote?) --- to be clear, the data presented
> so far is not raw data, but summary frequency data...which counts as
> statistical in one sense---but thus far, there is no statistical
> meaning derivable (in the sense of no testable hypothesis, and no
> meaningful analysis of the data forthcoming)...notice the word
> 'meaning' here --- statistics is about trying to convolve 'meaning'
> with 'measure'...and a great deal of contextual argument
> (hypothesizing) is necessary before its worthwhile even considering
> a 'statistical argument' as being a valid approach to a question
> (or problem set).

Interesting. Thank you for adding that. This is much of what I was
trying to get at. I don't really think that 'frequency data' is
statistical as such, but, in agreement with what you say, a step in the
direction towards it. Knowing that 5 out of 10 people in my neighborhood
buy Crest toothpaste tells me nothing. However, add demographic info and
dental records and it might. 

If the person who posted the original article would like to take the
challenge, I would be interested in seeing an on-line survey or
something along those lines to collect data and then prove/disprove the
earlier assumptions. This would be done with Perl of course :)

> note: I am not a statistician...though I have played one in a previous
> life...as such, all my remarks are within some bounded set of standard
> error and may, or may not, be incorrect.

cute.

e.

"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon."  R. Carver


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

Date: 17 Sep 1998 14:35:18 GMT
From: ka0osk@creighton.edu
Subject: win32:ODBC/Oracle->terrible perormance
Message-Id: <6tr6n6$sqj3@pigeon.creighton.edu>

In article <35FF75EB.C3D14EBF@deutschland.de>, Dirk Rottmar 
<rottmar@deutschland.de> writes:

>Hi,
>
>I just developed a cgi script which runs under NT 4.0 and connects to an
>Oracle 8.0 DB-Server (on the same machine) via ODBC (oracle driver) and
>win32:ODBC.
>
>My problem is, that my queries are incredibly slow, that means, that
>there are about 4000 datasets in a table. I do a SELECT which should
>return about 50 rows and it takes about 5 minutes to get the results
>:-(

This sounds like theres a problem somewhere.  Even flatfile CGI performance
is only about 15 secs for 50 rets on 4000 data items!

Is your server realy busy?
Do you have any unneeded looping going on?
You realy need to locate WHERE its bogging, there has to be a bottleneck.

John Step




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

Date: Wed, 16 Sep 1998 22:37:38 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Re: Y2K date in Perl
Message-Id: <360075F2.984FFEF2@sneex.fccj.org>

Milan Spingl wrote:
> 
> Hi there.
> What is the best way to get the system date? my $sdate=`date`; does not
> always work and localtime(time) does not include century. Prefixing the
> year with '19' is not an option as a Y2K comlpliancy is an issue. BTW, we
> run Perl 5.002 on a HP-UX 9.05 on a HP9000/735 box.
> Thanks...Milan

print localtime;

Has always proven nice :]

PS - Adding 1900 to the two digit year is very acceptable
for Y2k compliance (perl year is number of years since 1900;
but don't tell anyone, it's a secret and we would rather
have everyone keep asking this question :]

If ya don't believe me, please read about 300+ posts
covering Y2k issues via www.dejanews.com in various perl groups.

HTH,
-Sneex- 
__________________________________________________________________
Bill Jones | FCCJ Webmaster | http://webmaster.fccj.org/Webmaster
__________________________________________________________________
We are the CLPM... Lower your standards and surrender your code...
We will add your biological and technological distinctiveness to 
our own... Your thoughts will adapt to service us...
 ...Resistance is futile...


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

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

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