[6700] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 326 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 17 16:17:13 1997

Date: Thu, 17 Apr 97 13:01:52 -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 Apr 1997     Volume: 8 Number: 326

Today's topics:
     Re: perl and multithreading <khera@kciLink.com>
     Re: perl and multithreading <gnat@elara.frii.com>
     Re: PERL BUG: ([]) x 3 does not work correctly <gnat@elara.frii.com>
     Re: Puzzle: Count Actual Days from MM,DD,YYY to localti (Andreas Karrer)
     Re: question: How does one substitute into something ot (Bill)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and <weissman@gte.com>
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and <wclodius@lanl.gov>
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (Charles Lin)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (Paul Prescod)
     Re: slices in scalar context - bug or feature? <gnat@elara.frii.com>
     Re: Sorting files <gnat@elara.frii.com>
     Re: sybperl - rpc problem <mpeppler@mbay.net>
     Re: sybperl - rpc problem mpeppler@mbay.net
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 17 Apr 1997 12:13:43 -0400
From: Vivek Khera <khera@kciLink.com>
Subject: Re: perl and multithreading
Message-Id: <x7d8rtmxu0.fsf@kci.kciLink.com>

>>>>> "RSS" == Richard S Smith <rsmith@netcom.com> writes:

RSS> What's the difference between "multithreading" Perl and a Perl script that
RSS> uses fork() to do things in the background?  For example, in chapter 6 of

One can interpret the meaning of thread here as "lightweight process".
A thread is basically a separate execution pointer and stack operating
within the same program virtual memory space.  A traditional unix
process is then just a virtual memory space with one execution pointer
and stack.

Some people, notably the Plan-9 people, say that if you need
lightweight processes, your processes are too bulky... so they've
changed the meaning of what a process in Plan 9 is.



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

Date: 17 Apr 1997 12:47:00 -0600
From: Nathan Torkington <gnat@elara.frii.com>
Subject: Re: perl and multithreading
Message-Id: <5qrag932sb.fsf@elara.frii.com>


rsmith@netcom.com (Richard S. Smith) writes:
> What's the difference between "multithreading" Perl and a Perl
> script that uses fork() to do things in the background?

Multiple threads can run in one process, share all that process' data
and functions, and run in "parallel" within that process.  Threading
avoids the often-large expense of forking and allows much easier
sharing of data.  The traps are that access to shared data must be
regulated by mutex (mutual exclusion) locks, and functions must be
prepared to be re-entrant.  It can also make debugging your program
very hard, unless you have a thread-aware debugger.

That's what I've learned from the last week's worth of the
perl5-porters list, anyway :-)

Nat



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

Date: 17 Apr 1997 12:53:42 -0600
From: Nathan Torkington <gnat@elara.frii.com>
Subject: Re: PERL BUG: ([]) x 3 does not work correctly
Message-Id: <5qpvvt32h5.fsf@elara.frii.com>

xpress@pobox.com (Brian Dellert) writes:
> my($i, @chain);
> for($i=0; $i<@$pieces; $i++) {
> 	push @chain, [];
> }
> 
> Is there any more elegant/faster solution? My gut feeling is that
> there must be, but maybe this is my only bet.

You have to construct a new array reference many times.  Before, you
were constructing a new array reference, then copying it many times.
Any time you have to do something many times, you're looking at a
loop.

Some people would advocate:
	@chain = map { [] } @$pieces;
but the implicit loop (of map over @$pieces) means that (for me, at
least) the meaning doesn't just leap off the page.

In case you're wondering what the heck it does, here's a translation:
"For each element in @$pieces, return a new array reference.  Collect
these new array references in @chain".

Cheers;

Nat


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

Date: 17 Apr 1997 18:36:47 GMT
From: karrer@ife.ee.ethz.ch (Andreas Karrer)
Subject: Re: Puzzle: Count Actual Days from MM,DD,YYY to localtime(time) - REQ: Easier Way
Message-Id: <slrn5lcre1.4cl.karrer@kuru.ee.ethz.ch>


In article <3355a6f7.17526421@news.io.com>, rga wrote:

>($mday,$mon,$year) = (localtime(time))[3,4,5];
>      if ($mday < 10) { $mday = "0$mday"; }
>      $year = "19$year";

Please, if you must re-invent the wheel, don't re-invent the design
mistakes. Make that

   $year += 1900;

I start to believe the people who claim that the y2000 problem will
cost billions and billions of $; or milliards of CHF, DM, whatever.

 - Andi


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

Date: 17 Apr 1997 18:18:54 GMT
From: bill@sover.net.no.junkmail (Bill)
Subject: Re: question: How does one substitute into something other $_?
Message-Id: <slrn5lcqce.bno.bill@granite.sover.net>

In article <ysiz4td843r5.fsf@bufo.usc.edu>, Terrence M. Brannon wrote:
>
>Every example I have seen in \\(learning\\|programming\\) perl uses $_
>for the substiution examples. Hence I have no idea how to do
>substitution in other variables.
>
>Also, http://www.perl.org/perl/nmanual/pod/perlfaq.html will not
>respond.

   s/search/replace  is equivalent to $_ =~ s/search/replace.  Use $var 
=~ /pattern/ to operate on other variables.

						Bill
-- 
Sending me unsolicited email through mass emailing about a product or
service your company sells ensures that I will never buy or recommend your
product or service.


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

Date: Thu, 17 Apr 1997 13:10:54 -0400
From: Mark Weissman <weissman@gte.com>
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <3356599E.3F54@gte.com>

How about:

Iliad = 0
Bible = 1
Hamlet = 2
etc...
-- 
Mark Weissman
weissman@gte.com


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

Date: Thu, 17 Apr 1997 09:21:05 -0600
From: William Clodius <wclodius@lanl.gov>
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <33563FE1.2781@lanl.gov>

Richard A. O'Keefe wrote:
> 
> Douglas Seay <seay@absyss.fr> writes:
> >I'll agree that they aren't ivory tower languages, and that the language
> >specification may have been created hand-in-hand with the tool, but I
> >don't see how that makes them less of "languages".  This m ight be
> >ancient history, but was there a formal specification of COBOL, FORTRAN
> >or APL before the first implementation?]
> 
> COBOL   - yes.  (COBOL was "designed by committee".)
> Fortran - I _think_ the answer is 'yes'.
> APL     - most certainly!  Iverson's book preceded the implementation.
> <snip>

IF I remember Backus's paper in the proceedings of the first HOPL
conference, Fortran began as a brief proposal with some of the syntax
well defined, ie. simple arithmentic expressions, and the explicit
concepts of programs, functions and subroutines. It also must have
sketched some ideas as to how optimization was to be performed, because
that was a major thrust behind the language effort. However, several
aspects of the langage were not specified in any detail at all. The
syntax and implementation of I/O in particular was, I believe, left
primarilly to one team member who found that an interpreted
implementation was a good way to test his ideas, and then found when the
decision was made to ship Fortran (I) that he did not have time to
convert the I/O implementation to a compiled form. Interpreted I/O is
still used (in some contexts) in Fortran, because users foundthis
accidental feature to be useful. Also while Backus's original proposal
had the concept of subroutines this construct was not available in
Fortran (I), (after more than three years of work on a one year project
they had to get something out of the door and that aspect of the
language was not ready), but was instead introduced in Fortran II.

-- 

William B. Clodius		Phone: (505)-665-9370
Los Alamos Nat. Lab., NIS-2     FAX: (505)-667-3815
PO Box 1663, MS-C323    	Group office: (505)-667-5776
Los Alamos, NM 87545            Email: wclodius@lanl.gov


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

Date: 17 Apr 1997 17:53:46 GMT
From: clin@cs.umd.edu (Charles Lin)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <5j5o3a$9rn@mimsy.cs.umd.edu>

Erik Naggum (erik@naggum.no) wrote:
|| * Charles Lin
|| | If one had to choose a single type for everything, a string is a pretty
|| | good choice.  Why not a number?  How would you represent a string with a
|| | number?

|| excuse me?  what you call a "string" already _is_ a number.  computers
|| don't have characters.  display devices and printers do.

|| one of the first lessons of computer science _should_ have been internal
|| and external representation are so wildly different concepts that they
|| cannot even be confused, except, of course, by people who are fully aware
|| of the difference, but proceed to attempt to obliterate it.

     Egads.   You must have a slow newsserver.    You're at least the
third person to mention, plus there have been follow-ups to that, and
follow-ups to the follow-ups.   To summarize.   Yes, you can use
numbers to encode anything.   Computers use binary representations
for everything.   Second, no one would want to use numbers to program
in.   The point was given that a programming language has one type,
what would be the most convenient type to use.   If your only type
was integers, then strings would be a complete pain.   Just write
a program that just prints "Hello, world".   I don't think you want
to look up the ASCII representation just to force the use of numbers
as types.

--
Charles Lin
clin@cs.umd.edu



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

Date: Thu, 17 Apr 1997 16:27:04 GMT
From: papresco@csclub.uwaterloo.ca (Paul Prescod)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <E8sJ14.wG@undergrad.math.uwaterloo.ca>

In article <s6ypvvukubq.fsf@aalh02.alcatel.com.au>,
Chris Bitmead uid(x22068) <Chris.Bitmead@alcatel.com.au> wrote:
>While Lisp does not store numbers as strings, I never know or care
>that this is the case. In fact I could write a Lisp implementation
>that does store numbers as strings, and a programmer using it would be
>none the wiser (apart from awful performance of course). Why do you
>want to fit everything in a string?? It buys you NOTHING.

It buys you not having to write string->number. I don't think that this is a
big win, but I could see how it would be useful to people who are not used
to thinking about data types. Any programmer should run screaming from it,
but I can see its value for end users. That explains why apps embed TCL, but
not why programmers write whole programs in it.

 Paul Prescod




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

Date: 16 Apr 1997 12:37:10 -0600
From: Nathan Torkington <gnat@elara.frii.com>
Subject: Re: slices in scalar context - bug or feature?
Message-Id: <5qu3l63jc9.fsf@elara.frii.com>

(courtesy copy not emailed because Jim should be using a spam filter,
not hiding his email address from people he's asking help from)

robinson@see-my-sig.com (Jim Robinson) writes:
> An array in a scalar context will return the number of elements in
> the array. However, it seems that a slice in a scalar context will
> result in the last element of the array. Is this by design? I have
> looked thru 'info' for perl and I cannot find anywhere that would
> suggest what I am observing.

Tom explained this to me, recently, so I'm going to use you as a
guinea pig for my powers of explanation:

You're confusing a LIST and an ARRAY.  An ARRAY is a named sequence of
values, e.g. @users.  A LIST is an unnamed sequence, e.g. ("Tom",
"Nat", "Jim").  An ARRAY in a scalar context returns the number of
elements.  A LIST in a scalar context returns the last element.  A
slice is a LIST, not an ARRAY.

For even more confusing behaviour:

    sub a {
	return (4, 5, 6);
    }
    sub b {
	@a = a();
	return @a;
    }
    print scalar(a()), "\n";
    print scalar(b()), "\n";

This prints:
    6
    3

Nat


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

Date: 16 Apr 1997 12:53:06 -0600
From: Nathan Torkington <gnat@elara.frii.com>
Subject: Re: Sorting files
Message-Id: <5qsp0q3ilp.fsf@elara.frii.com>

tadmc@flash.net (Tad McClellan) writes:
> : How can I sort this inorder to
> : get the info from 2.6.97 before 10.2.97 and 11.2.97. 
> A really slow way (UNTESTED):

What you really want to do is turn the dates into
	YYMMDD
and sort those.  A naieve approach would be:

    sub compare_dates {
	my @a = split(/\./, $a);
	my @b = split(/\./, $b);
	my $yymmdd_a = sprintf("%0d%02d%02d", $a[2], $a[0], $a[1]);
	my $yymmdd_b = sprintf("%0d%02d%02d", $b[2], $b[0], $b[1]);
	return $yymmdd_a cmp $yymmdd_b;
    }
    sort \&compare_dates @dates;

but this would split and sprintf each date many times, because sort
calls compare_dates each time it has two dates to compare.

Quicker, then, to convert them all once, sort, then conver them back:

    sub date_to_yymmdd {
	my $date = shift;
	my @date = split(/\./, $date);
        return sprintf("%0d%02d%02d", $date[2], $date[0], $date[1]);
    }

    sub yymmdd_to_date {
	my $date = shift;
	my @date;
	$date =~ /^(..)(..)(..)$/;
	@date = ($1, $2, $3);
        return sprintf("%d.%d.%d", $date[1], $date[2], $date[0]);
    }

    @yymmdd = ();		# list of dates
    foreach $date (@dates) {
	push(@yymmdd, date_to_yymmdd($date));
    }

    @yymmdd = sort @yymmdd;

    @sorted_dates = ();
    foreach $yymmdd (@yymmdd) {
	push(@sorted_dates, yymmdd_to_date($yymmdd));
    }

This way you do two conversions for each element in the list, instead
of many many more than two: you convert it to YYMMDD form, you sort
the list using the default alphabetical sorting, and then you convert
the sorted list back to DD.MM.YY form.

This code isn't polished for speed or optimised for perl hackery, but
I was writing it so you could understand it without a brain meltdown
:-)

Nat


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

Date: Thu, 17 Apr 1997 10:47:14 -0700
From: Michael Peppler <mpeppler@mbay.net>
To: mpeppler@mbay.net
Subject: Re: sybperl - rpc problem
Message-Id: <33566222.43C1@mbay.net>

mpeppler@mbay.net wrote:
> 
> In article <3354F3EF.41C67EA6@gs.com>,
>   Daniel Roitman <daniel.roitman@gs.com> wrote:
> >
> > I just moved to a new server running perl5.003 and a newer version of
> > the Sybase modules, and my script (which worked fine under perl5.001)
> > started giving me the following warnings:
> >
> > 'rpcInfo' is not a valid Sybase::DBlib attribute at prodchar.cgi line 28
> 
> Yes, this is an old bug that showed up again, and that I should have
> sqashed ages ago :-(
> 
> You can rebuild sybperl without the -DDO_TIE option (see the CONFIG file)
> or get a patched version (2.07a) from http://www.mbbay.net/~mpeppler.

That URL should be http://www.mbay.net/~mpeppler

Sorry...

Michael
-- 
Michael Peppler, Data Migrations Inc.
mpeppler@mbay.net or mpeppler@bix.com


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

Date: Thu, 17 Apr 1997 12:21:44 -0600
From: mpeppler@mbay.net
To: daniel.roitman@gs.com
Subject: Re: sybperl - rpc problem
Message-Id: <861297516.16862@dejanews.com>

In article <3354F3EF.41C67EA6@gs.com>,
  Daniel Roitman <daniel.roitman@gs.com> wrote:
>
> I just moved to a new server running perl5.003 and a newer version of
> the Sybase modules, and my script (which worked fine under perl5.001)
> started giving me the following warnings:
>
> 'rpcInfo' is not a valid Sybase::DBlib attribute at prodchar.cgi line 28

Yes, this is an old bug that showed up again, and that I should have
sqashed ages ago :-(

You can rebuild sybperl without the -DDO_TIE option (see the CONFIG file)
or get a patched version (2.07a) from http://www.mbbay.net/~mpeppler.

Michael

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

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


Administrivia:

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

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