[7928] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1553 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 30 19:07:28 1997

Date: Tue, 30 Dec 97 16:00:39 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 30 Dec 1997     Volume: 8 Number: 1553

Today's topics:
     Re: 100.90  NOT  100.90000000000000568   HELP <zenin@best.com>
     Re: 100.90  NOT  100.90000000000000568   HELP (William R. Ward)
     Re: [Q ] What is wrong with @INC ????  Help please! <jdporter@min.net>
     Re: handling interrupts (Matthew Cravit)
     Re: Is Serial I/O possible in PERL? <tex@collegenet.spam-is-bad.com>
     Re: list as a hash value? (Sami Sandqvist)
     Re: list as a hash value? (Andrew M. Langmead)
     Re: Mysterious FileHandle + fork() behavior; possible P <achen@nssdc.gsfc.nasa.gov>
     Re: Mysterious FileHandle + fork() behavior; possible P <rootbeer@teleport.com>
     Re: Mysterious FileHandle + fork() behavior; possible P <achen@nssdc.gsfc.nasa.gov>
     Re: nntpd <zenin@best.com>
     Perl 5 and Win95 <amazon@wenet.com>
     Perl for Win32 under NT, IIS3, client is a mac! <vex1@concentric.net>
     PERLIPC - FIFO: parent, child, stalled! <jbattikha@highsynth.com>
     R/W Object access to main scope (Kory Lasker)
     Re: SHELL/REGEX GUNSLINGERS NEEDED!!! (Sami Sandqvist)
     Re: Which language pays most? Smalltalk, not C++ nor Ja <firewind@metroid.dyn.ml.org>
     Re: Which language pays most? Smalltalk, not C++ nor Ja (Kaz Kylheku)
     Re: Which language pays most? Smalltalk, not C++ nor Ja (Kaz Kylheku)
     Re: Which language pays most? Smalltalk, not C++ nor Ja (Robert Dewar)
     Re: word wrap routine (Gabor)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 30 Dec 1997 21:35:30 GMT
From: Zenin <zenin@best.com>
Subject: Re: 100.90  NOT  100.90000000000000568   HELP
Message-Id: <883517904.658487@thrush.omix.com>

William R. Ward <hermit@cats.ucsc.edu> wrote:
: Craig <design@kiwi.net> writes:
: > Sometimes when I make a calculation with Perl, it will do funny things
: > with the numbers. It will make a long decimal.

	All perl numbers are floats, long floats if I remember correctly.

: > I tried the int() function, but that's no good, because I need the two
: > decimals (money value)

	FAQ...! -Top of section 4 actually.  man perlfaq4

: > Does anyone know a function, or something, that will return my decimal
: > number "100.90000000000000568" back to "100.90" without using the printf
: > command ?

	What's wrong with (s)printf?

: If you want to round to the hundredths use this:
: my $rounded = int (( $orig * 100 ) + .5 ) / 100;

	Hmm...

	$rounded = sprintf ('%.2f', $orig);

-- 
-Zenin
 zenin@best.com


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

Date: 30 Dec 1997 15:18:53 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: 100.90  NOT  100.90000000000000568   HELP
Message-Id: <waabtxy2zdt.fsf@ese.UCSC.EDU>

Zenin <zenin@best.com> writes:
> William R. Ward <hermit@cats.ucsc.edu> wrote:
> : If you want to round to the hundredths use this:
> : my $rounded = int (( $orig * 100 ) + .5 ) / 100;
> 
> 	Hmm...
> 
> 	$rounded = sprintf ('%.2f', $orig);

You're right, that is actually faster.  I came up with the arithmetic
method because I thought it would be faster, but apparently it isn't.
Here's the results using Benchmark to time:

Benchmark: timing 100000 iterations of arith, sprintf...
    arith:  4 secs ( 4.66 usr  0.00 sys =  4.66 cpu)
  sprintf:  4 secs ( 3.57 usr  0.01 sys =  3.58 cpu)

The code:

use Benchmark;
use strict;

my $value = 0;
timethese(100000, {'sprintf' => "&round_sprintf",
                   'arith' => "&round_arith" });

sub round_sprintf
{
    $value += .0005;
    sprintf('.2f', $value);
}

sub round_arith
{
    $value += .0005;
    int (( $value * 100 ) + .5 ) / 100;
}
__END__

Note: I increment $value in each function to keep Perl from trying to
optimize for a constant $value (when I left $value alone, the results
favored sprintf even more: the arith method took over 3 times as long!

Why doesn't Benchmark accept CODE references for the code to execute,
I wonder?

--Bill.

-- 
William R Ward          Bay View Consulting   http://www.bayview.com/~hermit/
hermit@bayview.com     1803 Mission St. #339        voicemail +1 408/479-4072
hermit@cats.ucsc.edu  Santa Cruz CA 95060 USA           pager +1 408/458-8862
 PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt


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

Date: Tue, 30 Dec 1997 17:02:48 -0500
From: John Porter <jdporter@min.net>
Subject: Re: [Q ] What is wrong with @INC ????  Help please!
Message-Id: <34A96F88.479@min.net>

Augusto Cardoso wrote:
> 
> when I try to run Perl programs I get a message stating that PM files
> can not be found.
> @INC is displayed and it refers to the right LIB...
> Here is the error message:
> 
> Can't locate Pod/Text.pm in @INC <@INC contains:
> c:/perl/lib/os2/5.00455 c:/perl/lib c:/perl/lib/site_perl/os2
> c:/perl/lib/site_perl .> at c:\perl\bin/pod2text.cmd line 6.
> 
> File Text.pm is located in c:\perl\lib
> Would appreciate any good suggestions
> 
> Thanks

If you're sure that Text.pm is in \perl\lib, then that's the problem.
Move it down into the Pod directory; that seems to be
where it's expected to be.

John Porter
jporter@logicon.com


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

Date: 30 Dec 1997 13:51:21 -0800
From: mcravit@best.com (Matthew Cravit)
Subject: Re: handling interrupts
Message-Id: <68bqcp$dbb$1@shell3.ba.best.com>

In article <34A95D7C.D938603C@llnl.gov>, John Tannahill  <jrt@llnl.gov> wrote:
>In the cshell I used to handle interrupts as follows:
>
>onintr catch
>
>catch:

[Snip]

The %SIG array connects signals and their handlers. You can find out which
signals are available by looking at the man pages for signal on your 
system. Since I believe the onintr in csh is catching SIGINT, you could
do something like this:

sub SignalHandler { print "Caught a SIGINT - aborting!\n"; exit 255; }
$SIG{INT} = \&SignalHandler;

Hope this helps.

/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: Tue, 30 Dec 1997 14:13:53 -0800
From: Austin Schutz <tex@collegenet.spam-is-bad.com>
Subject: Re: Is Serial I/O possible in PERL?
Message-Id: <34A97221.624B@collegenet.spam-is-bad.com>

Arlen Fletcher wrote:
> 
> I need to communicate with a weather station via RS232.  I wasn't able to
> find any modules on CPAN that fit the bill...  Is serial I/O do-able in
> PERL?
> 
	Sure. A couple of modules that might be of use are the IO::Tty and
IO::Stty modules available on CPAN. Here's an example of how this might
work:

#!/usr/local/perl/bin/perl

use Fcntl; # For constants
use IO::Tty;
use IO::Stty;

$tty=new IO::Tty;
$tty->open('/dev/cua/a', O_RDONLY|O_NONBLOCK) || die "Couldn't open tty,
$!";
#$tty = new File;

IO::Stty::stty($tty,'raw',2400);

print $tty "ATH0\r"; # Hang up modem
# Wait a second for the modem to prosess the command.
sleep 1;
$response = <$tty>;
$response =~ 'OK' || die "Modem twiggled. No OK response";


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

Date: 30 Dec 1997 21:40:27 GMT
From: samiss@cc.tut.fi (Sami Sandqvist)
Subject: Re: list as a hash value?
Message-Id: <slrn6aiqig.316.samiss@ehdo.ton.tut.fi>

On 30 Dec 1997 20:24:31 GMT, Yung-Hsiang Lu wrote:
>Hi,
>
>Is there a way to store a list as a hash value?  It seems a very
>useful thing.  Here is an example to show the power of this feature:

Hash values are values, not lists. What you want is a hash of
references to lists. See man perldsc or perldoc perldsc ("HASH OF
LISTS"). 

>Guess the result of this code?

It seems you do not use the -w switch. Always use it. In this case, it
would have given warnings.

Sami
-- 
Sami Sandqvist - samiss@cc.tut.fi
Finger for PGP key.


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

Date: Tue, 30 Dec 1997 22:08:50 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: list as a hash value?
Message-Id: <EM0w6q.91u@world.std.com>

luyung@leland.Stanford.EDU (Yung-Hsiang Lu) writes:

>Is there a way to store a list as a hash value?  It seems a very
>useful thing.  Here is an example to show the power of this feature:

You can use references to create a "list of lists" or a "hash of
lists." See the perldsc man page ("Perl Data Structure Cookbook") for
details.

>$Sports{John} = ("swimming", "tennis", "football");
>$Sports{James} = ("tennis", "jogging");
>......

$Sports{John} = ['swimming', 'tennis', 'football'];
$Sports{James} = ['tennis', 'jogging'];

print "@{$Sports{John}}\n";
print "@{$Sports{James}}\n";
-- 
Andrew Langmead


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

Date: Tue, 30 Dec 1997 16:41:16 -0500
From: Allen Chen <achen@nssdc.gsfc.nasa.gov>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Mysterious FileHandle + fork() behavior; possible Perl bug?
Message-Id: <Pine.OSF.3.95.971230163638.7878D-100000@nssdc.gsfc.nasa.gov>

> 	if (not defined($pid = fork)) {
> 	    # Assume harmless fork failure
> 	    sleep 1;
> 	    redo;
> 	}

> After that block, the fork must have succeeded, so you need only check
> whether it's true or false. Does that fix the problem? 

Ah, I see.  Thanks for the pointers!  Unfortunately, that did not seem to
have any effect on my problem :(

It seems counterintuitive that the problem has anything to do with the
forking since the child processes don't use the filehandle that's getting
munged.  However, commenting out the fork lines fixes it (but also strips
out all the speed-ups), so I'm really boggled!

-Allen

Allen Chen   /   Systems Programmer    /   Hughes STX Corporation  ////
SSDOO Software, Systems / International Solar-Terrestrial Physics /////
e-mail: achen@nssdc.gsfc.nasa.gov   /     voice: (301) 286-7376  //////



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

Date: Tue, 30 Dec 1997 15:12:19 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Allen Chen <achen@nssdc.gsfc.nasa.gov>
Subject: Re: Mysterious FileHandle + fork() behavior; possible Perl bug?
Message-Id: <Pine.GSO.3.96.971230151010.7945I-100000@user2.teleport.com>

On Tue, 30 Dec 1997, Allen Chen wrote:

> It seems counterintuitive that the problem has anything to do with the
> forking since the child processes don't use the filehandle that's getting
> munged.  

They may not explicitly use it, but if a filehandle is open during the
fork, you may get duplicate output and other troubles. This is mentioned
in the docs for fork. Can you open the filehandle only after the fork? 
Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Tue, 30 Dec 1997 18:24:11 -0500
From: Allen Chen <achen@nssdc.gsfc.nasa.gov>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Mysterious FileHandle + fork() behavior; possible Perl bug?
Message-Id: <Pine.OSF.3.95.971230181333.7878E-100000@nssdc.gsfc.nasa.gov>

> > It seems counterintuitive that the problem has anything to do with the
> > forking since the child processes don't use the filehandle that's getting
> > munged.  
> 
> They may not explicitly use it, but if a filehandle is open during the
> fork, you may get duplicate output and other troubles. This is mentioned
> in the docs for fork. Can you open the filehandle only after the fork? 
> Hope this helps! 

The way the program works, the filehandle needs to be opened by the
parent.  As I understand it, after a fork, the child process gets a
duplicate set of the parent's file descriptors which point to the exact
same file table entries.  So even if I *did* use the filehandle in the
children, the file pointer should have the same offset throughout every
process and not cause any problems.

I am aware of possible duplicate output problems from unflushed buffers
and have taken care to prevent those.  Furthermore, the filehandle in
question is only used for reading, not writing.

I wonder, again, if this could be some kind of bug in Perl...

Thanks a lot for your input!
-Allen

Allen Chen   /   Systems Programmer    /   Hughes STX Corporation  ////
SSDOO Software, Systems / International Solar-Terrestrial Physics /////
e-mail: achen@nssdc.gsfc.nasa.gov   /     voice: (301) 286-7376  //////



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

Date: 30 Dec 1997 21:41:10 GMT
From: Zenin <zenin@best.com>
Subject: Re: nntpd
Message-Id: <883518244.449824@thrush.omix.com>

Benji Spencer <spunge@ripco.com> wrote:
: I would like to have a local nntpd type of setup on my LAN. The news
: servers I have looked at, do a lot more then what I want. I want to be
: able to use 'suck' on my Linux box, to retrieve the groups/articals I
: want, then use a news client on my win95 box to read the news from the
: Linux box. Are there any simple perl news servers that would work for
: this? I have looked, and maybe found a couple, but I am not sure if
: they will work at this moment.

	Run suck and INN on the Linux box.  INN really isn't that hard to
	install.  It should be a stock Linux port.

	Reinventing a full news server in perl would be redundant at best.

-- 
-Zenin
 zenin@best.com


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

Date: Tue, 30 Dec 1997 13:42:10 -0800
From: "G. Helms" <amazon@wenet.com>
Subject: Perl 5 and Win95
Message-Id: <34A96AB1.9016E51E@wenet.com>

I'm more familiar with Perl and IRIX than Perl and
Win95 (wave to Scott Henry)...but the time has come
to attempt to run Perl on a PC based Web server.

Question is: what are my best options?  I'm finding
lots of downloads for Perl on Win32, and I've been
told Win32==Win95....yet another doc I've found
says that Perl has problems with Win95, and one has
to hand-edit several files to get it to function.

The other issue is, I'd prefer to snag the binary version,
as I don't have any development compilers on this system.

Any tips?



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

Date: Tue, 30 Dec 1997 16:49:42 -0500
From: "Lon F. Binder" <vex1@concentric.net>
Subject: Perl for Win32 under NT, IIS3, client is a mac!
Message-Id: <34A96C72.D28D53E6@concentric.net>

I seem to be having a problem with one of my customers.

My server is an NT based, i386 machine, running MS' IIS 3.0 (soon going
to upgrade to 4.0).  I have been running Activestate's "Perl for Win32",
to get CGI to work on my server.  It has been alright, however, a recent
customer has described a problem he is having using the CGI from his
client.  He is accessing the web site from a Mac and is getting the
following error:
     You have started to dowload the file "phonesend.pl", of type
     "application/octet-stream". Check More Info to learn how to
     extend Navigator's applications.

My customer said that, "After clicking the More Info button I am taken
to the Netscape plug-in
finder that tells me that the plug-in application/octet-stream has not
been released for the Mac operating system."

Does anyone recognize this problem, or have any suggestions?


Lon F. Binder
webmaster, United Net Corp.
webmaster@unetusa.com
1-888-UNET-USA | http://www.unetusa.com






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

Date: Tue, 30 Dec 1997 16:15:59 -0500
From: Jihad Battikha <jbattikha@highsynth.com>
Subject: PERLIPC - FIFO: parent, child, stalled!
Message-Id: <34A9648F.1BEF0595@highsynth.com>

Can someone look this small script over and tell me what I'm doing
wrong?

All the paths and Unix commands exist on the server, so that's not it.
The FIFO is getting created, but the child process won't give back
control to the parent process and both processes stall.  Isn't the point
of a fork suppost to create separate _AND_ concurrent processes?  I
don't need much communication between the processes, I just need to have
a temporary FIFO managed by the child until the parent is done.  Then
kill off the child.  Seemed simple, but it's driving me nuts!

Eventually, the FIFO will supply text passed from STDIN, but for now I
kept it simple for testing:

---- start script ----
#!/usr/local/bin/perl

  pipe(FROM_CHILD, TO_PARENT);
  $pid = fork;
  $cid = $pid;

if ($pid == 0) {
  close(FROM_CHILD);
  chdir;
  $ENV{PATH} .= ":/etc:/usr/etc:/sbin:/usr/bin";
  $FIFO = "$ENV{DOCUMENT_ROOT}/temp/tempfile.tmp";
  print TO_PARENT $FIFO;
  while (1) {
    unless (-p $FIFO) {
      unlink($FIFO);
      system('mkfifo', $FIFO, 'p') || &error('mkfifo FIFO error');
    }
    open (FIFO, "> $FIFO") || &error('write FIFO error');
    print FIFO "Text to print.";
    close(FIFO);
    sleep(2);
  }
  exit(0);
} elsif (defined $pid) {
  close(TO_PARENT);
  print "Starting parent.\n";
  sleep(1);
  $FIFO = <FROM_CHILD>;
  $write = "$ENV{DOCUMENT_ROOT}/temp/write.txt";
    open (READ_FIFO, "< $FIFO") || &error('read FIFO error');
    open (WRITE_FIFO, ">> $write") || &error('write error');
      while (<READ_FIFO>) {
        print WRITE_FIFO $_;
      }
    close(WRITE_FIFO);
    close(READ_FIFO);
  sleep(2);
  $numKilled = kill('TERM', $cid);
  print "Killed child. Total processes killed = $numKilled.\n";
  unlink($FIFO) || &error('killing FIFO error');
  print "Deleted \$FIFO ($FIFO).\n";
  exit;
} else {
  &error('no process space');
}

sub error {
  my ($error,@error_fields) = @_;
  if ($error =~ /mkfifo FIFO error/) {
    print "There was a FIFO error: mkfifo FIFO error \$FIFO = $FIFO.\n";

  } elsif ($error =~ /write FIFO error/) {
    print "There was a FIFO error: write FIFO error.\n";
  } elsif ($error =~ /read FIFO error/) {
    print "There was a FIFO error: read FIFO error.\n";
  } elsif ($error =~ /killing FIFO error/) {
    print "There was a FIFO error: killing FIFO error.\n";
  } elsif ($error =~ /write error/) {
    print "There was a write error: culdn't write to $write.\n";
  } elsif ($error =~ /no process space/) {
    print "There was a process error: no process space.\n";
  } else {
    print "There was an unknown error.\n";
  }
  exit;
}
__END__
---- end script ----

I read all the docs on this including signals & general interprocess
communictions on Unix, etc. but I'm befuddled...I'm not getting any
errors -- the processes just hang.

--
Jihad Battikha
jbattikha@highsynth.com
http://www.highsynth.com



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

Date: 30 Dec 1997 23:10:18 GMT
From: koryl@math.umn.edu (Kory Lasker)
Subject: R/W Object access to main scope
Message-Id: <68bv0q$d67@epx.cis.umn.edu>

  I'm creating a plug-in interface to a program I'm working on that will
execute some class method at run-time.  Basically, I've allowed only read
access to the a tied() hash (%data) acting as a database within the
calling scope by doing this: 

# the "main" program
     eval {
        $obj = new $module ( $args );
        %{"${module}::data"} = %data; 
     };

# the plug-in file
package Plug-in;

%data;

sub new {
 my $class = shift;

 return bless $self, $class;
}

sub myFunc {
 my $self = shift;

 print join("\n", %data);

}

  Like this, I can access my tied hash (which is a cheap and easy form of
persistance for my cgi) from an object's scope because after Plug-in is
initialized, the main program copies the entire %data array over.  No,
this is not very efficient; I'd be willing to take an advice you may have 
to improve it, but it does work in a read-only sense.

  Now, however, I need to be able to read and write to the hash from an
object's scope.  I would like to simply declare a reference to the tied
hash from inside the object but this method hasn't worked for me.  Does
anyone have a good idea how I can implement this?  Ideally, I want to be
able to say $data{'a value'} = $query_res within an object and have those
changes take effect in the main scope of the running program.



--
 +-----------------------------------------------------------------------+
 | Kory Lasker - koryl@math.umn.edu  /\  http://www.math.umn.edu/~koryl/ |
 |   -- Math Department Systems Staff  \/  Office Phone: 624-7358 --     |
 +-----------------------------------------------------------------------+ 


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

Date: 30 Dec 1997 22:26:02 GMT
From: samiss@cc.tut.fi (Sami Sandqvist)
Subject: Re: SHELL/REGEX GUNSLINGERS NEEDED!!!
Message-Id: <slrn6ait7u.316.samiss@ehdo.ton.tut.fi>

On Tue, 30 Dec 1997 11:01:42 -0600, Rholder@sispost1.bis.adp.com wrote:
>I want to store regular expressions in one file, and then use a
>shell script to read them into a shell variable within a "for" loop,
>and then feed the expression into egrep via the shell variable.

Here you go. You get Perl in this newsgroup. It is poorly tested but
should work. It may not be self-documenting, but when you know how it
works you have learned some basics (and bad habits). HTH.

--------------------------------
#!/bin/perl -w
$REFILE = "refile";
$PSCOMM = "ps -eo pid,args |";

open REFILE or die ("Damn.");
open PSCOMM or die ("Damn.");

@relist = map {chomp;$_} <REFILE>;

while (<PSCOMM>) {
    for $regex (@relist) {
	if (/$regex/) {
	    print +(split)[0],"\n";
	}
    }
}
--------------------------------

Put these in the file 'refile'. Make sure it does not have an empty
line. I added the '-s' that seems to be preceding the second part of
the match.
-----------------
dataserver.*-smiler
dataserver.*-scitys
dataserver.*-sdemo
-----------------

>....and here is what is in the file /usr/local/scripts/pregex:
>
>'(dataserver).*(miler)+'
>'(dataserver).*(citys)+'
>'(dataserver).*(demo)+'

These look strange. Perhaps you would benefit from reading man perlre
or man egrep. I am particularly confused about your use of '+'.

>I don't want to write a long, ugly script with lots of individual egrep

I wrote you a short, ugly script. For the record, you can write clear
and elegant code in Perl.

Sami
-- 
Sami Sandqvist - samiss@cc.tut.fi
Finger for PGP key.


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

Date: Tue, 30 Dec 1997 14:58:02 -0700
From: firewind <firewind@metroid.dyn.ml.org>
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <Pine.LNX.3.95.971230145320.152B-100000@metroid.dyn.ml.org>

On Tue, 30 Dec 1997, Joshua Waxman wrote:

> On Mon, 29 Dec 1997, Guillermo Schwarz wrote:
> > very poorlanguage. You can't know how many bits does an int have. Or if long
> > is actually bigger
> > than int.

> You can't? How about sizeof(int) and if(sizeof(int) < sizeof(long))

sizeof(int) gives the size in bytes, which you need to multiply by
CHAR_BIT to get the number of bits.

> > You can't ask an structure how many fields does it have. 
> 
> True. But structures in C++ tend to have a constant number of fields, no?

And I'm curious as to the usefulness of this, anyway. How can you use a
structure that you don't know the layout of?

> > In C++ there is no way to handle overflow of integers.
> 
> Check after each addition to see if you reversed signs, and act
> accordingly.

What about unsigned arirthmetic? What if sign reversal is possible (but
not garunteed) in this expression, without any overflow?

[-                               firewind                                   -]
[-   email: firewind@metroid.dyn.ml.org (home), firewind@aurdev.com (work)  -]
[-          "You're just jealous because the voices talk to -me-."          -]
[-                   Have a good day, and enjoy your C.                     -]
[-          (on a crusade of grumpiness where grumpiness is due)            -]



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

Date: 30 Dec 1997 22:49:00 GMT
From: bill@cafe.net (Kaz Kylheku)
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <68btos$g7d$1@brie.direct.ca>

In article <34A812F9.C169A703@its.cl>,
Guillermo Schwarz  <gschwarz@its.cl> wrote:
>I'm sorry to hurt your feelings about C++. But it turns out that C++ is a
>very poorlanguage. You can't know how many bits does an int have. Or if long
>is actually bigger
>than int. You can't ask an structure how many fields does it have. You can't

Why would this be useful?

>tell an
>structure to write itself into a file. You can't code an algorithm that works

Why not? Have you never heard of object store databases? 

>with any
>kind of numbers: int, double, big int, etc.

Nonsense. You obviously haven't heard of C++ features such as templates,
and operator and function overloading.

>In C++ there is no way to handle overflow of integers.

An overflow is a serious programming error. The way you handle it is by not
making the error in the first place.  In C and C++, integer overflow invokes
undefined behavior---an implementation isn't required to handle overflow, but
may. 

You can detect overflows with assertions. I could lecture you how, but
it would probably be a waste of time. You first need to learn the basics,
like what a language standard is and how it differs from a compiler
manual.

>Ask in runtime how many classes do you have in your image.

I can't imagine what possible benefit it could have, but I will concede
that ``it's neat''.

>Or try to figure out which classes descend from which.

If you don't know which classes descend from which, you probably have a
mess of a design.

C++ is a _statically_ typed language; this gives it a performance advantage
and added safety (though the type safety of C++ does arguably leave
something to be desired.) Who writes high-performance applications in
Smalltalk?

>Try to make a single general program.

What's that? I'm conjuring images of something that plays chess and routes
IP packets at the same time.

>Try to create a Set of objects in C++.
>Try to create a Bag of objects in C++.
>Try to create a SortedCollection of objects in C++.

I'm not thorougly versed with the standard template library, but I believe
that it has enough clout for this sort of thing. If not, you can implement
your own classes. 

>Convert one collection into another. (SortedCollection as Bag or whatever).
>Put a Set inside another Set.
>Try to create a Dictionary of pairs of objects in C++ using hashing to index
>the keys.
>Then put a Dictionary and a Set inside a Dictionary with the Dictionary as
>the key.
>If you can do a single thing of what I wrote here you are a good C++
>programmer.

I've created dictionaries having arbitrary element and key types (including
self referential types) in the *C* programming language. 

In fact, I did them in my very first C programming project as an undergraduate
freshman, in which I had to implement an interpreter for a small PostScript
like language. In that language, it was possible to create dictionaries
that contain keyword and value pairs, where the values can be of dictionary
type.
 
>All this can be done in 10 minutes in Smalltalk (if lazy).

Yeah, and that's about how long it will take the executable to process
ten dictionary items.


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

Date: 30 Dec 1997 22:53:54 GMT
From: bill@cafe.net (Kaz Kylheku)
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <68bu22$geg$1@brie.direct.ca>

In article <Pine.A41.3.95.971230143114.19568A-100000@acis.mc.yu.edu>,
Joshua Waxman  <jwaxman@ymail.yu.edu> wrote:
>> In C++ there is no way to handle overflow of integers.
>
>Check after each addition to see if you reversed signs, and act
>accordingly.

That is absurd. Overflow invokes undefined behavior in C++. To check
for sign reversal, you would have to depend on a particular platform's
handling of overflow. On two's complement systems, overflow on addition or
subtraction can be detected by examining the most significant bit of the
result and those of the operands. This isn't true in general, however.

It's possible to determine whether a given operation will occur by
writing a test expression (or assertion) which itself does not invoke
overflow.


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

Date: 30 Dec 1997 18:14:11 -0500
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <dewar.883523608@merv>

<<> In C++ there is no way to handle overflow of integers.

Check after each addition to see if you reversed signs, and act
accordingly.
>>

Surely that is wrong, where in the C++ standard can you find a guarantee
on results obtained following signed numeric overflow?



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

Date: 30 Dec 1997 22:58:13 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: word wrap routine
Message-Id: <slrn6aiupa.69c.gabor@vinyl.quickweb.com>

In comp.lang.perl.misc, Joseph Cotton <jcotton@erols.com> wrote :
# Does any one have a routine to word wrap a $string ?
# I need to insert \n every 50 bytes or less, but not in the middle of a
# word.

here is a quick and dirty solution.
does  not address the problem of extra spaces at the beginning of
lines

undef $/;
$_=<>;
s/\n/ /g;
s/(.{50})(?=\s)/$1\n/g;
print;

gabor.
--
    I dunno, I dream in Perl sometimes...
        -- Larry Wall in  <8538@jpl-devvax.JPL.NASA.GOV>


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

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

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