[8877] in Perl-Users-Digest
Perl-Users Digest, Issue: 2495 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 4 18:06:40 1998
Date: Mon, 4 May 98 15:01:49 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 4 May 1998 Volume: 8 Number: 2495
Today's topics:
I/O to serial device <trachier@crrel.usace.army.mil>
is it possible to parameterize a class name? (Ed.Q.Bridges)
Perl Conference <wsanchez@tribune.com>
Perl Net App doesn't play well w/ C Net App <kirk.metz@waii.com>
Pre-extending a hash? (jeremy howard todd)
Re: Pre-extending a hash? <rootbeer@teleport.com>
Re: Pre-extending a hash? (Ilya Zakharevich)
Re: Regex Question (Craig Berry)
Re: Serial port ... again (Ken Irving)
sum/display sparse 3D array (RHS Linux User)
Re: sum/display sparse 3D array (Greg Bacon)
Was ANNOUNCE: Perl Builder IDE Now Available <shadowtracker@worsdall.demon.co.uk>
XSUB: shared libraries? <siddiqi-kaleem@cs.yale.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 04 May 1998 17:31:58 -0400
From: Gary Trachier <trachier@crrel.usace.army.mil>
Subject: I/O to serial device
Message-Id: <354E33CB.867E5BD2@crrel.usace.army.mil>
Hi All,
I am working on a UNIX system. I need to do I/O to a serial device;
specifically a modem that is connected as /dev/ttyb. I am using the
following program which uses pieces from the Perl FAQ. I find though
that the open() always fails. I know that the modem is not in use. Any
suggestions? Thanks very much.
use IO::Handle;
MAIN: {
my $modem = '/dev/ttyb'; # the modem device
my $response; # response from the modem
local *MODEM;
open (MODEM, "<+ $modem") || die ("Can't open $modem."); # open the
modem
print MODEM "ATZ\n"; # send something to it
MODEM->autoflush(1);
sleep 4;
print "Done sleeping.\n";
$response = <MODEM>; # read the response
print "\$response = $response";
close (MODEM); # close the device
}
-Gary T
------------------------------
Date: Mon, 04 May 1998 21:42:24 GMT
From: fakeuser@fakemail.com (Ed.Q.Bridges)
Subject: is it possible to parameterize a class name?
Message-Id: <354e3535.29291939@news.spry.com>
i'd like to do something like this:
#!/usr/bin/perl
$class_name = shift;
use ($class_name);
$object = new $class_name('Param1', 'Param2', 'Param3');
$object->PrintResults();
exit;
in more detail, i have many different classes for one program, that
have a consistent interface. i'd like to be able to determine at
runtime which class in particular is instantiated.
please cc responses to edb@interport.net
thanks
--e--
------------------------------
Date: Mon, 04 May 1998 17:12:52 -0400
From: William Sanchez <wsanchez@tribune.com>
Subject: Perl Conference
Message-Id: <354E2F54.B57F2813@tribune.com>
Can someone provide me with an ~ cost of attending the Perl Conference
last year.
TIA,
William Sanchez
Digital City South Florida
southflorida.digitalcity.com
------------------------------
Date: Mon, 04 May 1998 13:28:51 -0700
From: Kirk Metz <kirk.metz@waii.com>
Subject: Perl Net App doesn't play well w/ C Net App
Message-Id: <354E2503.41C6@waii.com>
I've written a very simple perl program in which I create a
socket,connect it to a listening daemon(written in C), send a small
amount of date over the connection with the send() call(no flags set),
and then close the connection. My listening daemon though won't return
the socket readable (from a select() call), but if I try to read the
socket in my listen daemon it reads the data fine from the perl script.
If I replace the perl script with a program written in C (that does
exactly what the perl script did), the daemon will return the socket
readable.
Is there something special I should know about perl and its behavior
with sockets?
I'm running Linux with kernel 2.0.18,Red Hat 4.0 on a x86 machine if it
makes a diff. The perl version I believe is 5.0.0.2
Thanks,
Kirk
Please respond with email as well as a post- my isp has very little hard
drive space, so it deletes "old" newsgroup messages very fast.
------------------------------
Date: 4 May 1998 20:09:34 GMT
From: jhtodd@students.uiuc.edu (jeremy howard todd)
Subject: Pre-extending a hash?
Message-Id: <6il79u$8kn$1@vixen.cso.uiuc.edu>
Okay, suppose you have a zillion keys and values you want to
stick into a hash table. You need to do some processing on each one
individually, so you can't slurp the whole list of values into the
hash at once. If we were talking about an array, since you know exactly
how many elements you're adding, you could pre-extend the array and save
some time.
My question is, is there something similar that could be done for
a hash (actually, a hash ref in my particular case)? From the benchmarks
I've run, at a rough guess it's taking 5-10 times as long to populate
the hash table (-not- counting the per-element processing) as to iterate
through (using each() no less) and modify every single element. I can
only assume this is due to the repeated reallocations the hash has to
perform as it grows to fit the data.
Any suggestions to speed this up? Memory usage is important
and the data set could be quite large, so I'd like to avoid storing any
redundant copies of the data, if possible.
Thanks!
-jht
--
Jeremy Todd Computer Programmer _,/
jhtodd@uiuc.edu ITCS On-line Development <__ \_.---.
http://www.cen.uiuc.edu/~jhtodd/ College of ACES, UIUC \_ / \
Zupfe Boy and Night Owl (And Kangaroo Aficianado) \)\ /\.\
=========================================================== // \\
"M-O-O-N, that spells moon" - Tom Cullen ,/' `\_,
------------------------------
Date: Mon, 04 May 1998 21:17:16 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: jeremy howard todd <jhtodd@students.uiuc.edu>
Subject: Re: Pre-extending a hash?
Message-Id: <Pine.GSO.3.96.980504141434.20962H-100000@user2.teleport.com>
On 4 May 1998, jeremy howard todd wrote:
> Subject: Pre-extending a hash?
If you have a rough idea of how many hash buckets you'll need, you may
assign to keys(%hash) directly. (If you don't know what hash buckets are,
don't worry; just use the number of keys you'd expect.)
keys(%hash) = 10000; # pre-extend the hash
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 4 May 1998 21:29:35 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Pre-extending a hash?
Message-Id: <6ilbvv$guj$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Tom Phoenix
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.3.96.980504141434.20962H-100000@user2.teleport.com>:
> If you have a rough idea of how many hash buckets you'll need, you may
> assign to keys(%hash) directly. (If you don't know what hash buckets are,
> don't worry; just use the number of keys you'd expect.)
>
> keys(%hash) = 10000; # pre-extend the hash
Just do not be surprized if the number of buckets after this call
becomes 16K. ;-)
Ilya
------------------------------
Date: 4 May 1998 20:04:45 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regex Question
Message-Id: <6il70t$53b$1@marina.cinenet.net>
Tod Thomas (tthomas@chubb.com) wrote:
: I have a string value that contains special characters. I want to pull
: out all of the characters up to the first special character, excluding
: it and any character following. For example:
:
: String contains: Test User (this is a test)
:
: I want to end up with Test User only. It looks easy but I've tried
: everything. Any help would be greatly appreciated.
First you need to decide on which characters are special; just for
example, let's say its (){}/ . Then given your text in $string, just do
$string =~ s/[(){}/].*$//;
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Mon, 04 May 1998 20:16:55 GMT
From: systech@polarnet.com (Ken Irving)
Subject: Re: Serial port ... again
Message-Id: <354e2130.153957178@news.ptialaska.net>
On 3 May 1998 14:40:14 GMT, mcai3ph2@ist4.co.umist.ac.uk (Pablo
Hortal) wrote:
>Hi,
>
>There have been many messages about how to write to / read from a serial port
>... but no one has actually provided any code that works ... or at least I
>haven't found it.
>
>I'm after some code to read data comming from the serial port (Windows 95
>system), I already know how to write to it.
>
>Some help on this will be appreciated.
>
>Thanks,
>Espinete.
>
I've posted this simplel example in the past. It works on Windows NT,
at least...
#!c:/perl/bin/perl -w
# modemATZ.pl 28,29jul97kci --- open modem port, send 'ATZ' to reset
# 3:49pm 26Jan98 kci -- added port spec on cmd line
use strict;
my ($echo, $reply) = ("","");
my $port = shift;
$port = "COM2:" unless defined $port;
open (MODEM,"+> $port") or die "unable to open modem port ($port)";
binmode MODEM;
select MODEM; #do not buffer output to MODEM
$|=1;
select STDOUT;
syswrite(MODEM, "ATZ\r", 4);
sysread(MODEM, $echo, 5);
print $echo;
sysread(MODEM, $reply, 10);
print $reply;
__END__
--
Ken
------------------------------
Date: 4 May 1998 15:19:20 -0600
From: sandy@armitage.nervana.montana.edu (RHS Linux User)
Subject: sum/display sparse 3D array
Message-Id: <6ilbco$9p5$1@armitage.nervana.montana.edu>
THE GOAL:
For a list of files that represent sparse 3D arrays
(of 100 x 100 x 100 integers) sum the values of all indecies that
contain a value. Ignore those indecies that contain no value in any input file.
PUNCHLINE:
Is there a way to display the sums without indexing
through all 1,000,000 possible slots, where (because these are sums of sparse
arrays that are geometrically similar) most indecies have no value.
Sample Data File:
where first 3 numbers in each row are x,y,z indecies of
a 3D array, that have the value of the last number.
10 40 44 2
11 50 51 4
13 41 47 8
13 41 47 9
22 62 35 3
#!/usr/bin/perl
##get the sums
while(<>)
{
chop;
@tokens=split;
if($arr[$tokens[0]][$tokens[1]][$tokens[2]])
{
$arr[$tokens[0]][$tokens[1]][$tokens[2]] += $tokens[3];
}
else
{
$arr[$tokens[0]][$tokens[1]][$tokens[2]] = $tokens[3];
}
}
## now the SLOW way to display the non-zero sums
for $x (0..99)
{
for $y (0..99)
{
for $z (0..99)
{
if($arr[$x][$y][$z])
{
print "$x $y $z == $arr[$x][$y][$z]\n";
}
}
}
}
--
/* sandy@nervana.montana.edu >--o0O>
* Center for Computational Biology
* Montana State Bozeman (406) 994-7061
* http://www.nervana.montana.edu/~sandy */
------------------------------
Date: 4 May 1998 21:50:18 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: sum/display sparse 3D array
Message-Id: <6ild6q$c34$11@info.uah.edu>
In article <6ilbco$9p5$1@armitage.nervana.montana.edu>,
sandy@armitage.nervana.montana.edu (RHS Linux User) writes:
: THE GOAL:
: For a list of files that represent sparse 3D arrays
: (of 100 x 100 x 100 integers) sum the values of all indecies that
: contain a value. Ignore those indecies that contain no value in any
: input file.
:
: PUNCHLINE:
: Is there a way to display the sums without indexing
: through all 1,000,000 possible slots, where (because these are sums
: of sparse arrays that are geometrically similar) most indecies have no
: value.
:
: Sample Data File:
: where first 3 numbers in each row are x,y,z indecies of
: a 3D array, that have the value of the last number.
:
: 10 40 44 2
: 11 50 51 4
: 13 41 47 8
: 13 41 47 9
: 22 62 35 3
Remember the good ol' days when real Perl hackers didn't need references
to do their dirty work? :-)
## construct sparse array from input
my %sparse;
while (<>) {
my($i,$j,$k,$d) = split;
$sparse{$i,$j,$k} = $d if defined $d;
}
## sum array
my $um = 0;
{
my $v;
$um += $v while (undef, $v) = each %sparse;
}
print "Cognito ergo $um\n";
When you need sparse, think `hash'.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Mon, 4 May 1998 22:14:12 +0100
From: Mark Worsdall <shadowtracker@worsdall.demon.co.uk>
Subject: Was ANNOUNCE: Perl Builder IDE Now Available
Message-Id: <UMZ6rbAk+iT1EwWG@worsdall.demon.co.uk>
I have tried this and I find it quite nice to use except:
When a program goes out of control there is no way of stopping it
When using keywords in "" they are considred keywords i.e. NEXT THEN and
IF when used in text strings.
If have noticed / monitored with WinTop that one can end up with
multiple sessions of perl.exe running.
It is slower than using a direct DOS session from within windows but
this is made up for in convenience with the o/p windows
--
Mark Worsdall (Webmaster) - WEB site:- http://www.shadow.org.uk
Shadow:- webmasterATshadow.org.uk
Home :- shadowwebATworsdall.demon.co.uk
Any opinion given is my own personal belief...
------------------------------
Date: Mon, 04 May 1998 16:08:45 -0400
From: Kaleem Siddiqi <siddiqi-kaleem@cs.yale.edu>
Subject: XSUB: shared libraries?
Message-Id: <354E204D.41C67EA6@cs.yale.edu>
I'm trying to write a C extension to perl, but am having trouble
with XSUB calls to functions defined in (a different) shared library.
Consider the following sample code contained in a file Dt.xs
#include<dt.h>
...
MODULE = Dt PACKAGE = Dt
void
EuclideanDt(width,height)
int width
int height
CODE:
{
Array_2D_double_t *aptr;
aptr = dtarr_New2dArray(height,width);
...
}
The structure Array_2D_double_t is defined in the
header file dt.h, and the function dtarr_New2dArray
is defined in a shared library libDt.so
Makefile.PL contains the following:
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Dt',
'VERSION_FROM' => 'Dt.pm', # finds $VERSION
'LIBS' => ['-L./lDT'], # e.g., '-lm'
'DEFINE' => '', # e.g., '-DHAVE_SOMETHING'
'INC' => '-I./', # e.g., '-I/usr/include/other'
);
When I run
perl Makefile.PL
make
everything seems to go through, and .blib/arch/auto/Dt/Dt.so
is created, in which a definition exists for EuclideanDt
However, a call to EuclideanDt from perl generates the complaint:
perl: error in loading shared libraries
./Dt/blib/arch/auto/Dt/Dt.so: undefined symbol: dtarr_New2dArray
Should I be explicitly loading the shared library libDT.so from
perl (in which dtarr_New2dArray is defined)?
Any pointers would be appreciated!
------------------------------
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 2495
**************************************