[6740] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 365 Volume: 8

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

Date: Thu, 24 Apr 97 15:00:23 -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, 24 Apr 1997     Volume: 8 Number: 365

Today's topics:
     Re: Any graphic module available? <mkruse@shamu.netexpress.net>
     Re: bug or feature ("my" semantics)? (M.J.T. Guy)
     Re: Calculating dates (Jason Lane)
     Re: Calculating dates (Matthew Cravit)
     Counting in a global search (David Waring)
     Re: Counting in a global search (Jason Lane)
     dynamic Perl fragment loading (Beth Alice Sundheim)
     GD 1.14 NT install problems <sys1mpo@is.ups.com>
     Generating math graphs on a WWW document <hjbortol@saci.mat.puc-rio.br>
     Re: Getting image size (Randy J. Ray)
     How to run FTP using Perl script <mjb@voodoo.ca.boeing.com>
     Re: How to run FTP using Perl script (Nathan V. Patwardhan)
     Re: Lisp is neither (was Re: Ousterhout and Tcl lost th (Kelly Murray)
     Re: multiple STDOUT formats <gnat@elara.frii.com>
     Network Programmin and Sockets <plussier@synnet.com>
     Object IDs are bad (was: Ousterhout and Tcl lost the pl <ludemann@inxight.com>
     Re: Ousterhout and Tcl lost the plot with latest paper <thant@nospam.acm.org>
     Re: Perl5 sin function has dain bramage ?!?!?!?!? <michaeli@dra.com>
     Re: Puzzle: Count Actual Days from MM,DD,YYY to localti (David Stoner)
     Randomly selecting lines of text? (Ted Pedersen)
     Re: Substitute (M.J.T. Guy)
     Re: switch and if <chrisp@nafohq.hp.com>
     Re: url_get on Solaris (Casper H.S. Dik - Network Security Engineer)
     Re: url_get on Solaris (Vic Abell)
     Re: What's the equivalent to sendmail with NT? (Neil Briscoe)
     When is ref($Some_Object_Reference) not $Some_Object? <gtk@walsh2.med.harvard.edu>
     Re: When is ref($Some_Object_Reference) not $Some_Objec (Ilya Zakharevich)
     Re: Who will win?  Borland or Microsoft or Programmers? yuka@co.tokyo.jp
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 24 Apr 1997 18:39:06 GMT
From: Matt Kruse <mkruse@shamu.netexpress.net>
Subject: Re: Any graphic module available?
Message-Id: <5jo9ca$e6o@news1-alterdial.uu.net>

Tom Phoenix <rootbeer@teleport.com> wrote:
: On 23 Apr 1997, fish wrote:
: > Is there any module that can handle this?
: If there is, it should be on CPAN. If it's not, you're welcome to submit
: one. :-) Hope this helps!

I would *really* like someone to continue working on my Graph.pm module 
at http://mkruse.netexpress.net/perl/

I think it's a really good start, and highly usable (I use it at work 
regularly for a variety of quick graphics needs).  but it needs to be 
explanded to support more options and more graph types.
Anyone wanting to do this, PLEASE mail me!

I dont have enough time to even think about working on it any more...

-- 
Matt Kruse
mkruse@netexpress.net
http://mkruse.netexpress.net/                       http://www.mkstats.com/
---------------------------------------------------------------------------


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

Date: 24 Apr 1997 18:52:27 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: bug or feature ("my" semantics)?
Message-Id: <5joa5b$829@lyra.csx.cam.ac.uk>

York Werres <werres@informatik.uni-bremen.de> wrote:
>
>Will 5.004 still require this workaround? (It puts the free
>variables into the same lexical layer.)

This and many other bugs with lexical scopes will be mended in 5.004.
The 5.004beta gives output "12" for all your examples.


Mike Guy


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

Date: 24 Apr 1997 15:07:47 -0400
From: jlane@pathfinder.com (Jason Lane)
Subject: Re: Calculating dates
Message-Id: <5job23$204@bilbo.dev.pathfinder.com>

In article <335F8A1E.6B12@io.com>, Dale Churchett  <daleweb@io.com> wrote:
>I'm trying to find out a way of converting a date returned by a call to 
>`date` to yesterdays date:
>
>$todays_date = `date`;
>
>$todays_date will obviously return the time and date the script
>containing this statement is being run, but I need to know the date in
>the same format and time zone for the previous day.
>
>I've searched through the man pages and looked at the strftime() command
>in C but can't work out how to do it. I was also told to try changing
>the TZ variable to 
>
>TZ=CST30CDT
>
>and then call `date` but that didn't work on my system.
>
>Any pointers would be greatly appreciated.
>
>Thanks in advance.
>
>Dale Churchett


Check out the localtime() function.  I use it to get yesterday's date all
over the place.

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
  localtime(time - (24 * 60 * 60)); # yesterday's date
-- 
--
Jason J. Lane                              jlane@pathfinder.com
Lead Application Developer                 212-522-9613
Time Inc. New Media                        http://www.pathfinder.com


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

Date: 24 Apr 1997 13:38:09 -0700
From: mcravit@shell3.ba.best.com (Matthew Cravit)
Subject: Re: Calculating dates
Message-Id: <5jogbh$8n2@shell3.ba.best.com>

In article <5jo8q8$u1@info.abdn.ac.uk>, Kyzer <dev.null> wrote:
>($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time-86400);

However, bear in mind that if localtime is evaluated in a scalar context,
it returns a formatted date string. So, you could do:

$yesterday = scalar(localtime(time-86400));
print "The date yesterday was: ", $yesterday, "\n";

And, yes, I realize the use of scalar in the above line is superfluous, 
but I usually put it in anyway to remind me of what I'm doing.

/MC

-- 
--
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@taos.com (work)     | time you make it.


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

Date: Thu, 24 Apr 1997 12:10:32 -0700
From: dwaring@fhcrc.org (David Waring)
Subject: Counting in a global search
Message-Id: <dwaring-2404971210320001@hal-6000.fhcrc.org>

This seems like a very obvious problem, but I can't find the answer anywhere.
If I search for a pattern in a globally can I find out how many times it
matched?

I want to count the number of times a particular character is found in a
single word string.  If this is possible, is it also possible in a
substitution (s/ / /) context?

Obviously this can be done looking at one character at a time, but I
figured it must be possible in a single line.

Thanks in advance

David Waring


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

Date: 24 Apr 1997 15:32:58 -0400
From: jlane@pathfinder.com (Jason Lane)
Subject: Re: Counting in a global search
Message-Id: <5jocha$23s@bilbo.dev.pathfinder.com>

In article <dwaring-2404971210320001@hal-6000.fhcrc.org>,
David Waring <dwaring@fhcrc.org> wrote:
>This seems like a very obvious problem, but I can't find the answer anywhere.
>If I search for a pattern in a globally can I find out how many times it
>matched?
>
>I want to count the number of times a particular character is found in a
>single word string.  If this is possible, is it also possible in a
>substitution (s/ / /) context?
>
>Obviously this can be done looking at one character at a time, but I
>figured it must be possible in a single line.
>
>Thanks in advance
>
>David Waring

Check out the 'g' operator (perl5 only) for regular expressions, i.e.:

#!/usr/local/bin/perl5 -w
 
$string = "abcdeabcdeabcde";
  
while ($string =~ m#abcde#g) {
  $count ++;
} 

print $count, "\n";
-- 
--
Jason J. Lane                              jlane@pathfinder.com
Lead Application Developer                 212-522-9613
Time Inc. New Media                        http://www.pathfinder.com


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

Date: Thu, 24 Apr 1997 16:05:51 -0400
From: bas15@cornell.edu (Beth Alice Sundheim)
Subject: dynamic Perl fragment loading
Message-Id: <bas15-2404971605520001@cu-dialup-1501.cit.cornell.edu>

Hello,

I have a Perl object that I would like to be a wrapper to create
user-defined objects (not meta-classing, just basic "roll-you-own
extensions").

Here's the idea


# $conf has info on where to find the user code and more
# this constructor loads a Perl fragment found in $path/user_code
# and makes DoSomething() execute that fragment
$obj = new Wrapper("user_code", $conf);

# this is a generic function that I want to be defined
# based on user_code
$obj->DoSomething();

So I'm looking to do something like AutoLoader, but not quite:
I don't want the new functionality to be accessible by any name
a la $AUTOLOAD: I want to define a single function to hold the
dynamically-loaded contents of a file. I want the user file to be pure
Perl, not a subroutine. My thoughts were

# load a user-provided subroutine definition from a file
open(USERCODE, $path_to_user_code);
@code = <USERCODE>;
eval "sub $user_code { @code }";
$user_code_function = &$user_code;

 ....

# execute the user-provided definition for DoSomething()
sub DoSomething() {
  goto &$user_code_function;
}

Is there a better way to do this? AutoLoader has

eval(require $path);
goto &$AUTOLOAD;

which I assume works because eval'ing the require'd subroutine definition
creates a new subroutine with the name $AUTOLOAD, which AutoLoader then
executes. Since my user contributed fragments will be just Perl without a 
sub name { } around them, I assumed that I could not "assign" the result
of requiring that file. Is this true or not true?

Please email to kdowney@octet.com. Thank you in advance for any assistance.

regards,
kd

-- 
Beth Alice Sundheim     
bas15@cornell.edu, sundheim@annie.wellesley.edu
http://annie.wellesley.edu/students/sundheim/sundheim.html


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

Date: Thu, 24 Apr 1997 14:04:10 -0400
From: "Michael P. O'Neil" <sys1mpo@is.ups.com>
Subject: GD 1.14 NT install problems
Message-Id: <335FA09A.AE4D9641@is.ups.com>

I am looking to install GD.pm for manipulating GIF files. The download
file that I am working with is from

http://www-genome.wi.mit.edu/ftp/pub/software/WWW/GDpm.zip 

The attached instructions require a new perl to be created by the
followinf steps:

C:\perl makefile.pl
c:\make perl
c:\make inst_perl

In this process I get the following message from the perl step:
 
Can't locate ExtUtils/MakeMaker.pm in @INC at makefile.pl line 1.

The version of perl I am running on NT 4.0 is perl5.003_07
Has anyone done the GD.pm install on NT 4.0?

Thanks,
Mike O'Neil


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

Date: Thu, 24 Apr 1997 18:36:55 -0300
From: Humberto Jose Bortolossi <hjbortol@saci.mat.puc-rio.br>
Subject: Generating math graphs on a WWW document
Message-Id: <335FD277.434@saci.mat.puc-rio.br>

Greetings!

I maintain a home-page for my pre-calculus students. It would be nice
to include the hability to generate graph of real functions. I mean,
the student specifies the formula and domain and  the program returns
the associated graph (in a GIF file).

Is there such software freely available? Perhaps a WWW interface program 

     (1) using GNUPLOT as external program or
     (2) using Maple V as external program or
     (3) using perl directly.

Any help is welcome!

Thank you very much in advance, 
Humberto.
hjbortol@saci.mat.puc-rio.br


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

Date: 24 Apr 1997 13:51:15 -0600
From: rjray@tremere.ecte.uswc.uswest.com (Randy J. Ray)
Subject: Re: Getting image size
Message-Id: <uowsp0gfbd8.fsf@tremere.ecte.uswc.uswest.com>


Assuming you are using Perl 5.002 or later, see:

http://mox.perl.com/CPAN/authors/id/RJRAY/Image-Size-2.3.tar.gz

This package (of mine) understands GIF, JPEG, XPM, XBM, PNG and the PPM series.
It can generate HTML tags, CGI.pm-style attribute lists, or just an (X, Y)
pair.

Randy
-- 
===============================================================================
Randy J. Ray -- U S WEST Technologies IAD/CSS/DPDS         Phone: (303)595-2869
                Denver, CO                                     rjray@uswest.com
"It's not denial. I'm just very selective about the reality I accept." --Calvin
===============================================================================


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

Date: Thu, 24 Apr 1997 18:42:39 GMT
From: Mehdi Beygi <mjb@voodoo.ca.boeing.com>
Subject: How to run FTP using Perl script
Message-Id: <335FA99F.167E@voodoo.ca.boeing.com>

I like to run a perl script to ftp a file from
a given server. When I run the following script 
the very first thing I get on screen is the following:
	Name (shaffer:mjb):
which I thought I am supplyin it and it fails. 
Any idea what is wrong and how to fix the problem.

 .
 .
 .
open(FTP, "|ftp $server");
print FTP $logname;
print FTP $pswd;
print FTP "cd $dir";
print FTP "get $filename";
close(FTP);

thanks
MJB


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

Date: 24 Apr 1997 19:39:17 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How to run FTP using Perl script
Message-Id: <5joct5$nlm@fridge-nf0.shore.net>


Mehdi Beygi (mjb@voodoo.ca.boeing.com) wrote:
: I like to run a perl script to ftp a file from
: a given server. When I run the following script 

[snip]

: which I thought I am supplyin it and it fails. 
: Any idea what is wrong and how to fix the problem.

Yes.  Get and install Net::FTP and all will be well.  :-)
Or write your own client which talks to an FTP server.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 24 Apr 1997 19:17:28 GMT
From: kem@math.ufl.edu (Kelly Murray)
Subject: Re: Lisp is neither (was Re: Ousterhout and Tcl lost the plot)
Message-Id: <5jobk8$e1d$1@sparky.franz.com>

In article <hbaker-2404970503060001@10.0.2.1>, hbaker@netcom.com (Henry Baker) writes:
>> 
>> In article <yd3esg6hqz.fsf@CLYDE.BOLTZ.CS.CMU.EDU>, Scott Fahlman
>> <sef@clyde.boltz.cs.cmu.edu> wrote:
>> 
>> > The Lisp Machines had a hellacious learning curve.  If you could
>> > invest the months required to learn all their tricks, they provided a
>> > software-development environment that has still not been surpassed.
>> > But even some accomplished Lisp programmers never had time to get over
>> > "the hump", and non-Lispers faced a really frightening barrier.
>> > The documentation was designed for people who already knew the answer,
>> > and Symbolics was remarkably unhelpful unless you wanted to spend a
>> > week and a few thousand dollars for a training course. 
>> 
>> Gee, the courses that Novell & many others teach cost as much or more,
>> and when you get out, all you know is some real niggly bit-pushing stuff.
>> 
>> I agree that the LispM documentation could have been better for beginners,
>> but I think that most would agree it left the documentation of most
>> competitors--including some pretty large companies--in the dust.

The later-years Symbolics documentation system was definitely excellent, 
and I understand it was one of their big assets when the company was sold,
and it was used successfully for non-lisp documentation purposes.

But before that (certainly in the ChinNual days), the system was clearly
for hackers only, with source code the ultimate documentation.  
Great stuff for hackers, but not for beginners.

-kelly murray 


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

Date: 24 Apr 1997 14:19:12 -0600
From: Nathan Torkington <gnat@elara.frii.com>
Subject: Re: multiple STDOUT formats
Message-Id: <5qiv1cfa2n.fsf@elara.frii.com>


"Richard S. Guse" <fxrsg@Camelot.acf-lab.alaska.edu> writes:
> How do I juggle multiple stdout formats?  If there are more than 1,
> they seem to eclipse each other.  Also, how do I envoke them?

Pages 124 and 125 of the new Camel (also found in the perlform
manpage) show how to do this.  In short, you assign to the
per-filehandle variables $^ and $~.  These are documented in the
perlvar manpage.

Nat


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

Date: Thu, 24 Apr 1997 11:47:25 -0400
From: Paul Lussier <plussier@synnet.com>
Subject: Network Programmin and Sockets
Message-Id: <Pine.GSO.3.96.970424113146.24140A-100000@pickett>


Hi all,

This is my first venture into network programming, and dealing with
writing client/server type scripts.  I took the 2 examples Tom C. wrote on
194-5 of the perlref .pdf file and began playing with them.  What I
couldn't figure out, was how I would pass parameters from the client to
the server.  All the examples seem to have the server configured to only
one thing (which is great for examples).  But, for instance, how could I
change Tom's example to accept different parameters?

Currently, the client connects to the server, and the server outputs to
the client:

	Hello there, <client name>, it's now <date>

I'd like to be able to pass command line args from the client to the
server.  For example, something like:

	client "ls -l /usr/local"

would pass the string "ls -l /usr/local" to the server, and the server
would return the "ls -l" output of /usr/local on that machine.  Obviously
my goal is to accomplis more than just a remote "ls" server :)

Any help would be greatly appreciated, or, any pointers to good docs on
into to client/server programming would be great as well (any one write
one in perl yet? :)

Thanks a lot

Seeya,
Paul
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Paul Lussier		=   It is a good day	=The next best thing to doing -
= 3Com S2 Division	-    to put slinkies	-something smart is not doing =
- plussier@synnet.com	=     on escalators	=      something stupid.      -
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
     =			      Interesting trivia:			-
     -   If you took all the sand in North Africa and spread it out	=
     =		 ...it would cover the entire Sahara desert.		-
      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=




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

Date: 24 Apr 1997 12:16:02 -0700
From: Peter Ludemann <ludemann@inxight.com>
Subject: Object IDs are bad (was: Ousterhout and Tcl lost the plot with latest paper)
Message-Id: <wujsp0gz0y5.fsf_-_@wistaria.i-have-a-misconfigured-system-so-shoot-me>

ark@research.att.com (Andrew Koenig) writes:

[snip]

> Here is a somewhat simplistic example.  The following ML code defines a
> binary-tree data structure where each node contains a value and is
> either a leaf or has two subtrees:
> 
> 	datatype 'a Tree = LEAF of 'a | TREE of 'a Tree * 'a Tree

[snip]

> But now suppose we want to be able to identify a specific subtree of a tree.
> If I had gone to the trouble of creating a tree abstraction in C++, I could
> identify a particular subtree by the address of its root.  But there's no
> corresponding facility in ML.  Trees are values, and although one can compare
> them for equality, there is no notion of object identity.

Absolutely correct and correctly so.

If two things LOOK the same, then they ARE the same.  It's called
"referential transparency" and it's a Good Thing, as opposed to
"pointers" which are a Bad Thing.  Why confuse your life with "object
identity"?

And why do you want to use the memory address for object identity to
identify it --- an address can change during garbage collection.  Why
not use a time stamp of object creation?  Oh, it's for efficiency
reasons, you say ... ah-ha!

But let's suppose that you really really really do need to identify a
particular subtree.  In other words, you want to NAME it.  No problem:
just create a dictionary (hash table) that maps names to subtrees.
That'll let you have two differently named entries which might happen
to have the same values.  And it won't expose pointers.  And it'll be
efficient.

Or, perhaps you need names attached to the nodes; then define:

	datatype 'a NamedTree = LEAF of 'a
	                      | TREE of string * 'a NamedTree * 'a NamedTree

It's trivial to translate between NamedTree and Tree and you can also
combine NamedTree with a dictionary to allow fast access to individual
sub-trees.

Repeat after me: "if two things look the same and act the same, then
they are the same".  Don't depend on some hidden property (pointer) to
differentiate them.  If there are important differences, then don't be
shy: bring them out in the open and NAME them.

[I once took an object-oriented database that used object-IDs and
translated it to a relational form which just used names for things;
performace improved by about about an order of magnitude.  But that's
another rant for another day ...]

-- 
Peter Ludemann		+1.415.813.6806  (fax: +1.415.813.7499)
Software Architect	ludemann@inxight.com
InXight Software, Inc.	http://www.inxight.com
PAHV 105, 3400 Hillview Ave., Palo Alto, CA 94304 


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

Date: Thu, 24 Apr 1997 12:23:00 -0700
From: Thant Tessman <thant@nospam.acm.org>
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <335FB314.167E@nospam.acm.org>

Andrew Koenig wrote:

> [...]  For example, I can write programs that manipulate trees and 
> tree-like data structures much more easily in ML than I can in C++, 
> as long as I stick to the operations that ML supports.  But it can 
> be useful sometimes to do things that ML doesn't support well, and 
> those things are much harder to implement in a language that has 
> trees virtually built in than in a language where trees are built 
> on top of a lower-level abstraction.

SML does not have trees "virtually built in."  Its type system 
understands discriminated unions.  This, plus pattern matching plus 
automatic memory management is what makes it so easy to build trees 
(and many other things) in SML compared to C++.

The *only* high-level semantic concept that C++ supports that SML
doesn't is (C++'s very awkward form of) subtyping polymorphism.  
And SML's support for generic polymorphism coupled with support for 
higher-order functions more than makes up for it.


> [...] But now suppose we want to be able to identify a specific subtree 
> of a tree.  If I had gone to the trouble of creating a tree abstraction 
> in C++, I could identify a particular subtree by the address of its root.  
> But there's no corresponding facility in ML.  Trees are values, and 
> although one can compare them for equality, there is no notion of object 
> identity.
> 
> One way to solve that problem is to use ML references for the tree nodes.
> But then the trees really do become objects, and treating them as values
> becomes much more difficult.  Moreover, I might not have thought I would
> need to identify particular subtrees, and changing an existing data structure
> to use references requires rewriting all of the code that uses it.
>
> [...]

I fail to see in what way C++ provides any advantage over SML in this 
example.  The problem of deciding what semantics your data structures 
should have doesn't get any easier merely because you're using C++.  
To the contrary, SML's type system is far more powerful than C++'s.  
This is what makes it easier to get data structure semantics right.  
Exposing memory addresses may provide a "built-in" concept of object 
identity, but only by imposing a huge memory management burden on the 
programmer, a far bigger burden than using refs in the (rare!) 
instances that you might need them.  (And adding a garbage collector
to C++ only addresses part of that burden.)

In contrast, it's easy to come up with examples of tasks that are 
trivial in SML and extremely difficult in C++.  I can't describe
what I'm working on, but I was recently glancing through "Design 
Patterns" by Gamma et al and happened to notice what they call the 
"Command" technique.  An entire chapter is devoted to something that 
can be accomplished *trivially* in any language that supports 
higher-order functions.  And I bet if I actually read more of the 
book I'd find it was nothing but a catalog of examples of why C++ 
sucks.


> Incidentally, this whole discussion talks only about language.  In
> deciding what programming tools to use, there is more than that to 
> consider.  After all, if all you care about is how easy the language 
> is for you to use, why not just invent your own language?  You won't 
> have a compiler for it unless you write one, but if ease of 
> programming is all you care about, that doesn't matter.   [...]

Since you mention it (even if only facetiosly), this is exactly what 
makes Scheme so great.  It is easy to implement mini-languages for 
specific problem sets.  My beef is that too many people who have
been trained to think in C/C++ don't even know that this is very
often exactly what they want to do.

Scheme has a simplicity and flexibility that SML doesn't have.  SML has
efficiency and safety that Scheme doesn't have.  Both make programming
in C++ feel like crawling through broken beer bottles in comparison.


> [...]  But even that is not all that matters.  There is also the 
> question of what tools your colleagues use, and what tools the people 
> might be using who will be maintaining your code, and what machines 
> you might be called on to support in the future.  [...]

In other words, C++ is better than SML because more people use C++
than SML?

-thant

[...followups trimmed...]


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

Date: Thu, 24 Apr 1997 17:32:14 -0400
From: Michael Iles <michaeli@dra.com>
Subject: Re: Perl5 sin function has dain bramage ?!?!?!?!?
Message-Id: <335FD15E.2A4A@dra.com>

David J. Topper (Pathfinder) wrote:
> sin(6.28318530717959) = -2.44929359829471e-16

Doesn't look too bad to me. Your value of pi*2 is off by
   .00000000000000352307471323344
(with less-significant digits truncated). You obviously want to get
zero back for the sin of pi*2, and given the above inaccuracy you
get back
  -.00000000000000244929359829471
which is pretty close to zero.

If you really want to get zero back, round it off to some number of
decimal places with sprintf.

Mike.

-- 
Michael Iles, michaeli@dra.com
Ceci n'est pas une .sig


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

Date: 24 Apr 1997 20:28:19 GMT
From: dstoner@marlin.utmb.edu (David Stoner)
Subject: Re: Puzzle: Count Actual Days from MM,DD,YYY to localtime(time) - REQ: Easier Way
Message-Id: <5jofp3$4ie@atlantis.utmb.edu>

rga (rga@io.com) wrote:


: Thanks !

: I put some work into a perl translation, but
: don't know C,  and I think I'm missing something
: here ... getting pretty invalid numbers as results.

: Anyone want to convert it ?

: >====================================================================
: >mon = (mon+9)%12;
: >if(mon>=10)
: >	year = year - 1;
: >pjul = (int)(year*365.25) + (int)(mon*30.6+0.5) + (day-1);
: >printf("%d\n",pjul);
: >
: >====================================================================

Following is a simple script to calculate a running day number $pjul given
the month, day of month and year (not taking into account that some
century years are not leap years) using the same method as above.  The day
number is fairly meaningless in itself; its values will be around 730,000
- roughly the number of days so far in the Christian era.  But further
calculations based on this number are useful.  For example $pjul % 7
correctly gives the day of the week: 0 for Sunday, 1 for Monday, etc.
(I've changed day-1 to $day+1 to make it come out that way.  The script
tells me I was born on a Friday, which is true.) The difference between
day numbers for two dates gives the number of days between those dates. 

I first implemented this procedure in APL over twenty years ago.  I think
the motivation was to find the date of the millionth day of the Christian
era, which was the subject of a science fiction story.  At the time, I
included all the bells and whistles, but the following is sufficient
for most practical purposes.

========================================================================
#!/usr/bin/perl
($month,$day,$year) = @ARGV;
$month = ($month + 9) % 12;
if ($month >= 10)
	{
	$year = $year - 1;
	}
$pjul = int($year*365.25) + int($month * 30.6 + 0.5) + ($day + 1);
print("day number is ",$pjul,"\n");
$wkday = $pjul % 7;
print("day of week is ",$wkday,"\n"); 
========================================================================

The reverse conversion (from day number to date) is equally simple,
though I haven't taken the time to re-invent that lately.  That would
make it easy to solve other problems, like finding the date of a day
n days from today, or deciding whether today is the last day of the
current month.

The forward and reverse conversion probably also give you a validity
check on dates:  convert a given date to day number and back to date.
If the result is what you started with, it's a legitimate date.

David

__
UTMB Information Services
David.Stoner@utmb.edu
dms@atlantis.utmb.edu dstoner@marlin.utmb.edu  usenet@utmb.edu news@utmb.edu
help@marlin.utmb.edu




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

Date: 24 Apr 1997 20:28:46 GMT
From: pedersen@seas.smu.edu (Ted Pedersen)
Subject: Randomly selecting lines of text?
Message-Id: <5jofpu$d04$1@hermes.seas.smu.edu>



Doe anyone have a Perl program that will randomly select (without
repetition!) a given number of lines from a text file?  

Thanks! 
Ted

---
* Ted Pedersen                     pedersen@seas.smu.edu              * 
*                                  http://www.seas.smu.edu/~pedersen/ *
* Department of Computer Science and Engineering,                     *
* Southern Methodist University, Dallas, TX 75275      (214) 768-3712 *





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

Date: 24 Apr 1997 19:36:39 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Substitute
Message-Id: <5joco7$bi5@lyra.csx.cam.ac.uk>

David Alan Black <dblack@icarus.shu.edu> wrote:
>
>Elegant solutions-are-us  :-)
>
>orig = '%Test%';
>$Test = "This is a string\n";
>
>$orig =~ s/%(.*?)%/$$1/g;
>
>The two main modifications here are (1) the use of the
>non-greedy quantifier *?, and (2) the $$1 syntax, which
>symbolically dereferences (desymbolically references?)
>$1.

Elegant solutions are one thing.   Correct ones are another.   That won't
substitute ${$1}.   It'll substitute ${$}1, which probably isn't what you
want.

In 5.004, this sort of thing will attract a warning

Use of "$$<digit>" to mean "${$}<digit>" is deprecated at - line 3.

but in 5.003 you suffer in silence.


Mike Guy


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

Date: Thu, 24 Apr 1997 14:10:06 -0700
From: Chris Pratt <chrisp@nafohq.hp.com>
Subject: Re: switch and if
Message-Id: <335FCC2E.2C60@nafohq.hp.com>

There is no 'switch/case' structure in Perl.  You can get the
same effect by using 'and do's.

I think that the Camel book states that there's no difference between
the two-- the compiler turns both into lookup tables-- but I slapped a
test together to find out.  The results surprised me.  If/elsifs were
significantly faster than the 'and' construct I used.

Here's my test code:
use Benchmark;

$x = 8;

timethese( 100_000, { 'if-then' => <<END_IF_THEN, 'andswitch' =>
<<END_ANDSWITCH,});
if ($x == 1) { "one\n"; }
elsif ($x == 2) { "two\n"; }
elsif ($x == 3) {  "three\n"; }
elsif ($x == 4) {  "four\n"; }
elsif ($x == 5) {  "five\n"; }
elsif ($x == 6) {  "six\n"; }
elsif ($x == 7) {  "seven\n"; }
elsif ($x == 8) {  "eight\n"; }
END_IF_THEN
SWITCH: {
($x == 1) and  "one\n", last SWITCH;
($x == 2) and  "two\n", last SWITCH;
($x == 3) and  "three\n", last SWITCH;
($x == 4) and  "four\n", last SWITCH;
($x == 5) and  "five\n", last SWITCH;
($x == 6) and  "six\n", last SWITCH;
($x == 7) and  "seven\n", last SWITCH;
($x == 8) and  "eight\n", last SWITCH;
}
END_ANDSWITCH
__END__

And here're my results:
Benchmark: timing 100000 iterations of andswitch, if-then...
 andswitch:  0 secs ( 1.18 usr  0.00 sys =  1.18 cpu)
   if-then:  0 secs ( 0.45 usr  0.00 sys =  0.45 cpu)

I just slapped this script together; there may be problems with
it that I don't know about.



Alastair Aitken wrote:
> 
> iqbal gandham wrote:
> > Chipmunk wrote:
> > > In article <335E3B6E.39D8@prestel.net>
> > > iqbal gandham <igandham@prestel.net> writes:
> > >
> > > > Is it better to use an if statement or switch, or doesn't it make much
> > > > difference.
> 
> > > You are absolutely right about that.  There is no reason to use
> > > multiple if/else statements like that in Perl, when Perl's switch
> > > statement will do the same thing much more efficiently.
> > >
> 
> Ok - confused now.  I thought, as Abigail said, that there was no
> switch/case statement in perl and
> that effective switch/case statements coud be written using
> if/elsif/else constructs.
> 
> I think Chipmunk is wrong here .. or amd I?
> 
> Alastair.


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

Date: 24 Apr 1997 21:06:21 GMT
From: Casper.Dik@Holland.Sun.COM (Casper H.S. Dik - Network Security Engineer)
Subject: Re: url_get on Solaris
Message-Id: <casper.861916237@uk-usenet.uk.sun.com>

Jeff Seaton <j.m.seaton@larc.nasa.gov> writes:

>I've got url-get working under SunOS 4.1.3, but I am now trying to get
>it to work on a Solaris machine with Perl5.003, and whenever I run it
>with a simple test case (./url_get "http://www-genome.wi.mit.edu/") I
>get the error message chat'open(www-genome.wi.mit.edu, 80): Protocol not
>supported"  In the chat package (chat2.pl), the error is occurring on
>the statement:   socket(S, 2, 1, 6)


You're missing "use Socket;"  Check your socket() manual page then check
your Solaris include files; you'll find that socket(2,1,6) makes no
sense on Solaris.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.


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

Date: 24 Apr 1997 20:01:20 GMT
From: abe@cc.purdue.edu (Vic Abell)
Subject: Re: url_get on Solaris
Message-Id: <5joe6g$7mm@mozo.cc.purdue.edu>

Jeff Seaton <j.m.seaton@larc.nasa.gov> writes:

>I've got url-get working under SunOS 4.1.3, but I am now trying to get
>it to work on a Solaris machine with Perl5.003, and whenever I run it
>with a simple test case (./url_get "http://www-genome.wi.mit.edu/") I
>get the error message chat'open(www-genome.wi.mit.edu, 80): Protocol not
>supported"  In the chat package (chat2.pl), the error is occurring on
>the statement:   socket(S, 2, 1, 6)
			       ^
			       |
			       + -- Could it be that this is the wrong
				    type?  SOCK_STREAM, for example,
				    is 2 in Solaris 2.5.1 and 1 in
				    SunOS 4.1.3c. SOCK_DGRAM is 1 in
				    Solaris 2.5.1; 2, SunOS 4.1.3C.

>Anyone know what I'm missing?

>Please email me at j.m.seaton@larc.nasa.gov


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

Date: 24 Apr 1997 21:15:56 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: What's the equivalent to sendmail with NT?
Message-Id: <memo.19970424221613.10537A@skep.compulink.co.uk.cix.co.uk>

In article <335ebd3e.818655@news.onramp.net>, ranger@onramp.net (Gregory
Reddin) wrote:

> Hi all:
>
> I've moved from a Unix based web server to Windows NT. Now,  my perl
> scripts that use sendmail don't work anymore.  What can I use on NT
> that's the equivalant to sendmail?
>

There is a direct port of a Unix Sendmail to NT but it's commercial.
Visit http://www.metainfo.com - its very good - and you can happily call
it using sendmail -t, for example, and it works just like the Unix one
would.
 
> Also, each of these scripts used to create a log file but this doesn't
> work either.
>
> Any help would be greatly appreciated.
>

More info. required on that.  How do they attempt to create the log files?

Regards
Neil



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

Date: 24 Apr 1997 15:51:12 -0400
From: Gregory Tucker-Kellogg <gtk@walsh2.med.harvard.edu>
Subject: When is ref($Some_Object_Reference) not $Some_Object?
Message-Id: <w2pvvkp5cf.fsf@walsh2.med.harvard.edu>


I have the following code, using my own 'NMR' modules:

  #!/bin/perl -w

  use lib '.';
  use Fcntl;
  use File::Basename;

  use NMR::PeakFile;

  $HSQC = "hsqc.peaks";

  $hsqc = tie(%hsqc,'NMR::PeakFile',$HSQC,O_RDONLY);

  foreach $num (sort { $a <=> $b} keys %hsqc ) { 
    my $peak = $hsqc{$num};
    printf "%3d %30.30s %s\n", $num,$hsqc{$num},$peak;
    printf "%3d %30.30s %s\n", $num,ref($hsqc{$num}),ref($peak);
  }

Each entry in %hsqc contains a reference to a peak object, which is
created during the tie.  But the output of the program gives:

  2   NMR::Peak=HASH(0x1009920c)    NMR::Peak=HASH(0x1009920c)
  2                                 NMR::Peak
  3   NMR::Peak=HASH(0x100993b0)    NMR::Peak=HASH(0x100993b0)
  3                                 NMR::Peak
etc.

Why isn't ref($hsqc{$num}) defined?  I thought that ref($hsqc{$num})
should be "NMR::Peak".

--
Gregory Tucker-Kellogg
Department of Biological Chemistry and Molecular Pharmacology
Harvard Medical School, Boston MA 02115
"Mojo Dobro"    Finger for PGP info



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

Date: 24 Apr 1997 21:02:07 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: When is ref($Some_Object_Reference) not $Some_Object?
Message-Id: <5johof$idp$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Gregory Tucker-Kellogg 
<gtk@walsh2.med.harvard.edu>],
who wrote in article <w2pvvkp5cf.fsf@walsh2.med.harvard.edu>:
> 
> I have the following code, using my own 'NMR' modules:
> 
>   #!/bin/perl -w
> 
>   use lib '.';
>   use Fcntl;
>   use File::Basename;
> 
>   use NMR::PeakFile;
> 
>   $HSQC = "hsqc.peaks";
> 
>   $hsqc = tie(%hsqc,'NMR::PeakFile',$HSQC,O_RDONLY);
> 
>   foreach $num (sort { $a <=> $b} keys %hsqc ) { 
>     my $peak = $hsqc{$num};
>     printf "%3d %30.30s %s\n", $num,$hsqc{$num},$peak;
>     printf "%3d %30.30s %s\n", $num,ref($hsqc{$num}),ref($peak);
>   }
> 
> Each entry in %hsqc contains a reference to a peak object, which is
> created during the tie.  But the output of the program gives:
> 
>   2   NMR::Peak=HASH(0x1009920c)    NMR::Peak=HASH(0x1009920c)
>   2                                 NMR::Peak
>   3   NMR::Peak=HASH(0x100993b0)    NMR::Peak=HASH(0x100993b0)
>   3                                 NMR::Peak
> etc.
> 
> Why isn't ref($hsqc{$num}) defined?  I thought that ref($hsqc{$num})
> should be "NMR::Peak".

If you think you found a bug in perl, you need to provide more info
about your perl (perl -V), and a one-liner (using standard tools)
which reproduces the bug.  

I would think that your NMR::PeakFile just does not produce anything
on the second access.

Ilya


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

Date: Thu, 24 Apr 1997 13:43:53 -0700
From: yuka@co.tokyo.jp
Subject: Re: Who will win?  Borland or Microsoft or Programmers?
Message-Id: <335FC609.7E92@co.tokyo.jp>

Actually Borland should vanish because their compilers are too good.  It
make programming so easy that in 2 years their will be no need of
programmers like myself. Think about it, after all their are finite
amount of computer program human kind may need, like (WP dBase, Invoice,
etc.)  It is expected that after few years their will be no more
programs to write because Microsoft and other big companies will write
programs that will serve everyones need.  Bad news for programmers.


pit@aol.com wrote:
> 
> chas@aol.com wrote:
> >
> > What the hell does this have to do with all these irrelevant news
> > groups.
> > Someone stop cross posting.
> 
> Looks like as long as Microsoft will exist, there will be no peace in the world.
> 
> >
> > chas@aol.com wrote:
> > >
> > > mac@macsofta.com wrote:
> > > >
> > > > > M A wrote:
> > > > >
> > > > > Hi,
> > > > >         My company is planning to start a project.  We have a big question
> > > > > about our investments.  We don't know if we should use Microsoft
> > > > > compiler or Borland.  Some myth we heard over the net.
> > > > >
> > > > > 1) 90% of the programmer uses Microsoft Compiler.
> > > > > That's absoutly untrue for now and future..
> > > > ---90% uhh, since when.  I just looked up TRST report and that says 50%
> > > > Microsoft, 30% Borland, and 20% all others...
> > >
> > > Sounds Good!
> > > > > > 2) Borland will vanish in 2 years (NASDAQ:BORL)
> > > > > Borland's bad finicial situation was issused four years ago,  somebody
> > > > > said Borland will vanish in 2 years, and 4 years passed, look what's
> > > > > happening?
> > > >
> > > > That won't happen.  Look at Netscape.  It is still alive and running
> > > > faster then ever.
> > > Boland is the technological leader and can't vanish in 8 years.
> > > > > > 3) Borland has better compiler
> > > > > Well, they have the fastest compiler for C++ (C++Builder), TOP
> > > > > RAD(Delphi) and Very Very Fogotten but a very very professional and
> > > > > powerful Visual dBase..  Actually, they have better compiler..  But
> > > > > language itself is not only compiler..(Forget I didn't metion both
> > > > > Borland and Microsoft doesn't support mulitiple-platform, yet..)
> > > >
> > > > Entera or what ever from Borland will set the standard for next 10
> > > > years.
> > > What is Entera?
> > > > > > 4) 99% of the College in US have/use Borland Compiler.
> > > > > That's absoutly untrue, either..
> > > > Well it more like 80%.
> > > Do I care.
> > > > > If you want to choose project between Borland and Microsoft, my
> > > > > suggestion is depended on what do you actually need.  Actually, if you
> > > > > wnat to make DOS-GAMES, window PE and all kinds of mutiple-platform PC
> > > > > apps, choose Borland C++ 5.1 (VC++ doesn't support these platform
> > > > > anymore..)  if you want RAD, choose Delphi.  If you are using MS-Office
> > > > > (which is the top office suite), choose VB.  If you have a bunch of
> > > > > people accustomed to MFC class library, choose VC++..
> > > > >
> > > > > And also, if you are using Linux, UNIX, X windows, SUN, and others, IBM
> > > > > visual Age is the best choice..
> > > > >
> > > > > >
> > > > > > Some one show us the way?
> > > > > >
> > > > Don't worry about the size of Microsoft.  Your company need productivity
> > > > so go for Borland.  After all if you have a good product it will make up
> > > > all the investment during the first 6 month.  I have seen project
> > > > written in VB and VC.  I know the difference it make. Don't let
> > > > Microsoft wash your brain.  They are only good and Marketing and hypeing
> > > > the shit out of a product.  MacOS is much superior then Win97.  Se ya
> > > Wait a min.  If you say UNIX 6 VS NT 4.1 then I would agree.


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

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

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