[8571] in Perl-Users-Digest
Perl-Users Digest, Issue: 2188 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 26 16:08:36 1998
Date: Thu, 26 Mar 98 13:00:29 -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 Thu, 26 Mar 1998 Volume: 8 Number: 2188
Today's topics:
ANNOUNCE: Decision::Markov 0.01 <alansz@uic.edu>
ANNOUNCE: Math::MagicSquare 1.10 module <pivari@geocities.com>
ANNOUNCE: Win32::Tie::Ini <rothd@xrxoxtxhx.xnxextX>
Re: Anybody experienced in File-Locking with Perl5? (Michael J Gebis)
Re: babelfish.altavista web client (enjoy) (Craig Berry)
Re: Bidirectional Filehandle??? <barnett@houston.Geco-Prakla.slb.com>
Re: books? (User)
Re: Challenge your programming skill (Abigail)
Re: Challenge your programming skill (Bart Lateur)
Re: Creating a unique id number? <jhi@alpha.hut.fi>
Re: Days of the Week (Gregory Snow)
EP3 - The Extensible Perl PreProcessor <spivey@erols.com>
find command equivalent in Perl sadri@macsch.com
Re: hard reference, variable names ? (Mike Stok)
Help unpacking Little-Endian shorts and longs <Clinton.Bodine@mci.com>
Re: Object destruction order non-deterministic? (Jason Gloudon)
Re: Odd-Numbered Array to Hash (Mike Stok)
Re: Odd-Numbered Array to Hash <ptimmins@netserv.unmc.edu>
Re: Odd-Numbered Array to Hash (Bart Lateur)
Re: Odd-Numbered Array to Hash <upsetter@shore.net>
Perl Programmer needed in San Jose, CA <benjamin@cgusa.com>
Re: Perl versus Python benchmark-results <akuchlin@cnri.reston.va.us>
Perl5 DBLIB RPC <ken.chesak@dhs.state.tx.us>
Re: PerlRing??? (Tye McQueen)
Re: PROPOSAL: The Perl Dictionary <rkoehler@osmre.gov>
Re: regular expression (Craig Berry)
Re: removing eval from a loop <jalukas@lucent.com>
ts: why have "push" and "unshift"? tsatan@hotmail.com
Re: ts: why have "push" and "unshift"? <jhi@alpha.hut.fi>
using quot in Net::FTP to chmod <kab@mail.utexas.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Mar 1998 19:16:45 GMT
From: Alan Schwartz <alansz@uic.edu>
Subject: ANNOUNCE: Decision::Markov 0.01
Message-Id: <6fe9it$it9$1@news1.teleport.com>
I have just uploaded the Decision::Markov module, version 0.01 to
CPAN.
The suggested module list line is:
Name DSLI Description Id
------------- ---- -------------------------------------------- ------
Decision::Markov bdpO Build/evaluate Markov models for decisions ALANSZ
>From the README file:
Decision::Markov - Markov models for decision analysis
Copyright (c) 1998 Alan Schwartz <alansz@uic.edu>. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
DESCRIPTION
This module provides functions used to built and evaluate Markov models
for use in decision analysis. A Markov model consists of a set of
states, each with an associated utility, and links between states
representing the probability of moving from one node to the next. Nodes
typically include links to themselves. Utilities and probabilities may
be fixed or may be functions of the time in cycles since the model began
running.
PREREQUISITES
Decision::Markov expects to find some core perl modules, notably
FileHandle and Carp.
INSTALLATION
perl Makefile.PL
make
make test
make install
REVISION HISTORY
0.01 March 1988 - Initial concept.
FUTURE PLANS
I'm planning to wire this up as the back end to CGI scripts for
teaching Markov models using web-based simulations. Future revisions
may include some other ways to display the model, and perhaps a
Monte Carlo routine that will run the model X times and produce
useful statistics (mean, variance, 95% CI, etc.)
There may also be other Decision:: models in the future, such
as Decision::Tree, Decision::Influence (influence diagrams),
Decision::Utility (utility assessment) and Decision::Bayes
(Bayesian updating of priors based on diagnostic tests).
But I may not get to them soon. Feel free to get there before me!
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Alan Schwartz <alansz@uic.edu>
Asst. Prof. of Clinical Decision Making | University of Illinois at Chicago
Adj. Asst. Prof. of Psychology | Department of Medical Education
"Life is what happens to you while you're busy making other plans"
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 26 Mar 1998 19:17:47 GMT
From: Fabrizio Pivari <pivari@geocities.com>
Subject: ANNOUNCE: Math::MagicSquare 1.10 module
Message-Id: <6fe9kr$itt$1@news1.teleport.com>
What is Math::MagicSquare module?
The first purpose of this PERL module is to help you to check your
Square, to answer these questions
Is it a Semimagic Square?
Is it a Magic Square?
The second purpose of this PERL module is to help you to print your
Square.
At the moment the method available is 'print' that prints the square on
STDOUT.
I'd like to add
- printhtml (to print the square in HTML format)
- pringif (to print the square in a GIF image)
- prinpdf (to print the square in PDF format)
What is a Magic Square?
Do you like Magic Square?
Do you want to know more information about Magic Square?
Try to visit
A very good introduction on Magic Square
http://www.astro.virginia.edu/~eww6n/math/MagicSquare.html
A whole collection of links and documents in Internet
http://www.pse.che.tohoku.ac.jp/~msuzuki/MagicSquare.html
A good collection of strange Magic Square
http://www.geocities.com/CapeCanaveral/Lab/3469/examples.html
The only Magic Square checker and gif maker in Internet (I think)
http://www.geocities.com/CapeCanaveral/Lab/3469/squaremaker.html
What's new with version 1.10
Added Panmagic Square test in check method
Where can I find it?
http://www.geocities.com/CapeCanaveral/Lab/3469/Math-MagicSquare.html
is the primary location
You also can find it at CPAN archive
Enjoy it!
Send me your suggestions.
--
Fabrizio Pivari
mailto:pivari@geocities.com
http://www.geocities.com/CapeCanaveral/Lab/3469/
Member of ANFACE Software
http://www.geocities.com/CapeCanaveral/Hangar/4794/
------------------------------
Date: 26 Mar 1998 19:17:20 GMT
From: "Dave Roth" <rothd@xrxoxtxhx.xnxextX>
Subject: ANNOUNCE: Win32::Tie::Ini
Message-Id: <6fe9k0$itm$1@news1.teleport.com>
So here it is. A brand spankn' new extension that allows
you to tie
a hash with an INI file. Pretty cool!
Basically you have full access to INI files (create your
own, modify
existing ones).
Even though INI files are on the way out and the registry
is being
used more and more this provides a template if someone
wants to
modify it to allow for a Win32::Tie::Registry extension.
That would
be cool!
Have a look:
ftp://ftp.roth.net/pub/ntperl/tieini/980311/
Cheers,
dave
--
============================================================
====
Dave Roth ...glittering
prizes and
Roth Consulting endless compromises,
shatter
rxoxtxdxxrxoxtxhx.xnXeXt the illusion of
integrity
My email address is disguised to fool automailers. Remove
the
X's to send me email.
************************************************************
****
Use of this message or email address for commercial
purposes
(including "junk" mailings) is strictly prohibited and
protected
under current international copyright laws and United
States
Code, Title 47, Chapter 5, Subchapter II.
------------------------------
Date: 26 Mar 1998 18:24:26 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Anybody experienced in File-Locking with Perl5?
Message-Id: <6fe6gq$3lg@mozo.cc.purdue.edu>
aml@world.std.com (Andrew M. Langmead) writes:
}Tobias Bugala <TobiasBugala@swol.de> writes:
}>well I should lock a file so that only one process can access that file.
}>I'm using HP-UX and I've written a testing code like this:
}>Do you know where my fault is? I tested it by running the script two
}>times in different windows and it prints the file in both of them...
}Have you seen the "How can I lock a file?" entry in the FAQ?
}<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq5/
}How_can_I_lock_a_file_.html>
File locking is one of those parts of UNIX that other folks can point
to and say "What's _THAT_ mess about?" It's confusing, works
differently across venders, and breaks in bizarre ways under NFS. All
is not lost, but you might want to read up on file locking under UNIX
first (not just file locking under perl).
_Advanced Programming in the UNIX Environment_ by Stevens has a pretty
good introduction to file locking.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: 26 Mar 1998 17:57:06 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: babelfish.altavista web client (enjoy)
Message-Id: <6fe4ti$8ib$1@marina.cinenet.net>
Matija Grabnar (matija@rzenik.arnes.si) wrote:
: In article <35180766.BB4ADDA3@shopcfn.com>,
: Dan Boorstein <dboorstein@shopcfn.com> wrote:
: >based on the results i would like to recommend:
: >
: >MTTOTTOTTOTTTOTTTOTTTOTHTOTOWOTMI
: >
: >as a new perl slogan.
: >
: >i think it will make for easier translation back into portugese,
: >thereby fostering a closer connection to perl developer base in
: >portugal. ;)
:
: Yeah, and as apparently every Italian knows,
: "There are more of the one-way for the farlo."
I much prefer the earthy Spanish simplicity of "Tiene mas una forma para
hacerlo" ("It has plus a form to do it"). Oddly, this seems to support
the view that Perl is primarily a CGI implementation language.
---------------------------------------------------------------------
| 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: Thu, 26 Mar 1998 12:05:15 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Bidirectional Filehandle???
Message-Id: <351A98DB.C93FAC27@houston.Geco-Prakla.slb.com>
Tobias Bugala wrote:
>
> Hi,
>
> I have a file in wich a incremeting number is saved. Now I should open
> it once for Read AND Write.
>
> I tested something like:
>
> ...
> open (FILE, "+>$filename") or die ...
---------------^^
This could cause you much pain and anguish. According to the perldoc -f
open data:
If the filename begins with '<' or nothing, the file is
opened for input. If the filename begins with '>', the
file is truncated and opened for output. If the filename
begins with '>>', the file is opened for appending. You
can put a '+' in front of the '>' or '<' to indicate
that you want both read and write access to the file;
****** thus '+<' is almost always preferred for read/write
****** updates--the '+>' mode would clobber the file first. The
These two lines are very important. Opening the file as "+> $filename"
empties $filename before proceeding to do anything else with it. "+<
$filename" on the other hand just opens the file.
I don't know what other problems you might face.... Beware the multiple
simultaneous access (concurrency) issue. You should look into flock.
HTH.
<SNIP>
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
------------------------------------------------------------------------
* Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------
------------------------------
Date: Thu, 26 Mar 1998 17:34:55 GMT
From: you@somehost.somedomain (User)
Subject: Re: books?
Message-Id: <351a9168.267147778@news.btinternet.com>
Ok base level get perl for dummies, doesn't cover everything, but a
nice easy way in, and fairly MS biased, then the Gekko and then the
Camel, (Learning Perl for Win32, and programming Perl)
Ian
On 25 Mar 1998 13:43:52 GMT, scott@softbase.com wrote:
>bob tokarsky (btokar@freespace.net) wrote:
>> Can anyone recommend a good book for exploring PERL on a win95 system.
>
>Sure can. Go to www.skwc.com/essent/cyberreviews.html and
>look for the Windows 95 Book FAQ. I've tried to list
>all the books that have anything to do with Perl on Windows.
>
>> I would like to learn Perl and CGI on my machine at home before i
>> download my programs to the cgi-bin directory on my ISP.
>
>This has nothing to do with Perl itself. I've never seen a single,
>solitary book about getting Perl CGI scripts running under the Personal
>Web Server or even IIS. (Anyone who would write this could
>make a bundle of money, hint hint.)
>
>Scott
>--
>Look at Softbase Systems' client/server tools, www.softbase.com
>Check out the Essential 97 package for Windows 95 www.skwc.com/essent
>All my other cool web pages are available from that site too!
>My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: 26 Mar 1998 17:50:53 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Challenge your programming skill
Message-Id: <6fe4ht$cc8$1@client3.news.psi.net>
Bart Lateur (bart.mediamind@tornado.be) wrote on MDCLXVIII September
MCMXCIII in <URL: news:351a02cc.679806@news.tornado.be>:
++ Hasan Diwan wrote:
++
++ > Residents living close together have the same zip code. New
++ >York's upper west side (where my uncle lives) is 10019, however world
++ >trade centre is 10023.
++
++ I've been a little bref in my other post. Let me recapitulate. This is
++ this thread so far in short:
++
++ Kim Lo asked about finding "the closest customer name based on an input
++ zipcode. I have the data file containing zipcode, state, longitude and
++ latitude in a database already."
++
++ TomH proposed "it would be more accurate to get cartesian vectors to the
++ zipcode and customer from the center of the earth and take the dot
++ product between them (this gives the cosine of the earth central angle)"
++
++ to which Abigail replied that this would be unreliable when people live
++ in clusters: "Clusters of humans are sometimes called cities. If your
++ customers are clustered, your approach doesn't work well.".
Nope. I didn't say anything about unreliable. I would fully agree with
TomH that using the dot product gives better results (if used with enough
precision).
The original problem was to avoid trying all customers. The number of
customers is the problem. Now any algorithm that subdivides on a pattern
independant of the set of users doesn't garantee to help: clustering of
the clients. In fact, any algorithm that needs to scan all customers to
see if they are in some confined area is pointless. If you're going to
scan all customers anyway, you might as well calculate the distance from
the query point and get your answer in one scan. Scanning all customers
is what we are trying to avoid.
++ I also must confess I had misread TomH's post. Now I see that he
++ mentioned the "dot product". I thought he had written "vector product",
++ wich would be a far more sensible approach, as the result is
++ proportional to the SINE of the angle. Of course it's a vector, but you
++ can easily take the length of that.
cos (a,b) = (a . b) / (|a| * |b|).
Under the assumption that the earth is a sphere, |a| * |b| will be the
same for all customers. So, taking the dot product *makes* sense.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Thu, 26 Mar 1998 18:36:53 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Challenge your programming skill
Message-Id: <351a9f32.422977@news.tornado.be>
Abigail wrote:
>cos (a,b) = (a . b) / (|a| * |b|).
>Under the assumption that the earth is a sphere, |a| * |b| will be the
>same for all customers. So, taking the dot product *makes* sense.
Assuming that both points are close together, cos(a,b) will be very
close to 1. That makes the precision quite low.
cos(a,b) ~ 1 - square(theta)/2
with theta the angle between a and b in randians. It's theta you're
interested in, not cos(a,b).
In contrast:
sin(a,b) ~ theta
(note: I used "~" to represent "is almost equal to").
Bart.
------------------------------
Date: 26 Mar 1998 19:51:32 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: Creating a unique id number?
Message-Id: <oeelntxz6fv.fsf@alpha.hut.fi>
I am *NOT* interested in fork() speed, a job _startup_ time. I am
interested in task completion time. Okay, one can proof that yes, it
is possible to `exhaust the pid pool' and to force a wraparound in
subsecond. But show me a server that _completes_ >30k "average" *)
jobs in subsecond, the throughput. Yeah, this interest of mine is not
any more directly relevant to the original idea of using a pid as part
of an id...
Personally I wouldn't use just the getpid() and the time() for
anything serious ids (and which aren't), too few bits (15 + 31), both
too predictable (getpid() in too many systems monotonic, the time()
definitely monotonic), the first one wraps around too fast. I would
use subsecond timers (gettimeofday(), gettimer()), more environmental
noise (in a UNIX box, "ps axl", "vmstat -s", "netstat -an", ...), any
nice randomish jitter (I/O / network delays), all that compressed (to
cut down redundancy), and cryptographically "smeared", with e.g. MD5.
*) such as compiling gcc, all the three stages :-)
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: 26 Mar 1998 18:08:37 GMT
From: snow@biostat.washington.edu (Gregory Snow)
Subject: Re: Days of the Week
Message-Id: <6fe5j5$th2$1@nntp6.u.washington.edu>
If you don't want to get the module(s), then here is another
possibility: Convert the date to Julian day then mod 7 it. You will
probably need to run today or another day that you know the answer to
in order to find out which is day 0 (and I have no idea if it will
work for dates before the Julian/Gregorian switch). Below is a
subroutine for computing Julian days originaly posted by Jeff Godden
and pulled off of DejaNews.
>or if you're like me, a module-weenie (too much bloat/too much "module
>X must be installed to get module Y"), just use the following
>subroutine with your eyes open to it's deficiencies:
>
># ----- this will return day number 719469 for 1970/1/1
>sub jday {
> # note screwed up american date element ordering
> my($month,$day,$year) = @_;
> my($y) = $year + ($month-3)/12;
> int(367*$y+0.625)-2*int($y)+int($y/4)-int($y/100)+int($y/400)+$day;
>}
In article <6fe1k3$q4f$1@nnrp1.dejanews.com>, <schwern@starmedia.net> wrote:
>use Date::DateCalc qw(day_of_week);
>
>print day_of_week(1998, 3, 26); # Thursday, March 26, 1998
>
>
>Note the minor trap there. DateCalc uses 1 as January. Localtime uses 0 as
>January.
>
>http://www.perl.com/CPAN/modules/by-module/Date/
>
>In article <890790681.73936@satin.sensation.net.au>,
> "Mike Barnes" <strepsil@very.net> wrote:
>>
>> Anyone out there got a neat little snippet of code, or just a method I can
>> use to find out what day of the week a given date fell on?
>>
>> I wouldn't have the faintest idea where to start, but that's mainly because
>> I haven't memorised all the rules from leap years/centuries...
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/ Now offering spam-free web-based newsreading
--
-------------------------------------------------------------------------------
Gregory L. Snow | MATZ'S RULE REGARDING MEDICATIONS:
(Greg) | A drug is that substance which, when injected
snow@biostat.washington.edu | into a rat, will produce a scientific report.
------------------------------
Date: 26 Mar 1998 19:18:43 GMT
From: "Gary Spivey" <spivey@erols.com>
Subject: EP3 - The Extensible Perl PreProcessor
Message-Id: <6fe9mj$iud$1@news1.teleport.com>
Announcing EP3 - the Extensible Perl PreProcessor.
(Text::EP3)
For those in the perl arena, if you have need of a preprocessor that uses
perl - here is one ...
The unique aspect is its extensibility - every directive is simply a perl
method. As perl blocks can be evaluated within the text being processed, new
directives can be embedded in the code itself (also via outside modules if
desired).
For those in the HDL arena,
This code was written to provide a preprocessor for verilog (will be
equally as useful for VHDL). Why another preprocessor? I wanted something
that would let me specifiy port lists in one location rather than the 10-15
required in a module and its test bench. By declaring a signal directive, I
was able to define port lists in many different formats and have them
automatically processed in both the test bench and the module file. The
include directive has been modified so that optionally, only specific
portions of code will be included. This is useful for including parameters,
functions, port list specifications, whatever - without the need to cart
around some extra file (functions.v, etc.). Also, all of the evaluations are
done by perl - so an eval directive gives you full use of perl (so logs and
base two thingys can be calcluated in your code - good for bit widths). As
the if structures also use perl, you can do a whole lot more than simply if
A==B, you can do checks to see if files exists for inclusion - like "if -e
file.con" for including constraint files. Comment processing can be turned
on and off so that you don't accidentally blow away something in an embedded
synopsys file.
If you do the test bench and module correctly, you can have modules where
you specify port list is one spot, the behavioral code itself, and the
stimulus in the test bench. Everything else can be autogenerated ... no more
output/input/reg/wire/reset/display/do it again in the test bench/initial
values/ etc. One spot. The way it should be. The new verilog98 should
obviate the need for a little of this, but not enough.
Another nice feature is the ability to embed perl blocks in the code. More
than just a generate. A lot more. I used it to define a hash table for a
fully paramterized wallace tree multiplier. More than I could do with a
generate and/or for loop.
Anyway, for those who might find it useful, it is available on CPAN as
Text::EP3
For the verilog extensions (and a few other verilog directives) you also
need
Text::EP3::Verilog
For those who can't yet navigate CPAN, these can also be found for the time
being at
www.ee.umd.edu/~spivey
Should any VHDL users care to submit VHDL directives, I would be more than
happy to include them in another release. The same goes for any more verilog
directives ...
Cheers,
Gary Spivey
DOD
spivey@romulus.ncsc.mil
------------------------------
Date: Thu, 26 Mar 1998 14:16:55 -0600
From: sadri@macsch.com
Subject: find command equivalent in Perl
Message-Id: <6fecui$470$1@nnrp1.dejanews.com>
Hello Folks;
I am writing my first Perl Script on WinNT to look inside my temp directory
and list all files within the directory and subdirectories which are over 5
days old. So far I could read the content of directory temp but not the
subdirectories. Eventually I like to sort the content in reverse order and
assign the result to an Array.
Is there a nice and easy way of doing this without writing lines of code to do
this task? I have a Korn Shell script that does that and I 'd like to do thee
samething with Perl. I use something like this in Korn Shell:
find ./ -type d -a -mtime +5 -print | sort -u -r
I was wondering if there was an equivalent Korn shell command "find" in Perl.
I would appreciate any help.
Thanks in advance!!!
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 26 Mar 1998 18:11:32 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: hard reference, variable names ?
Message-Id: <6fe5ok$qp5@news-central.tiac.net>
In article <3519F24A.A7CB89AC@coos.dartmouth.edu>,
Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:
>I'm surprised no one has suggested this solution. Apparently, everyone is
>stuck thinking inside the box. ;-)
>
>($sex eq 'M' ? $M{$offer} : $F{$offer}) = $sth->fetchrow_array;
maybe
${$sex eq 'M' ? \%M : \%F}{$offer} = $sth->fetchrow_array;
of if you're allowing symbolic refs
${$sex}{$offer} = $sth->fetchrow_array;
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Thu, 26 Mar 1998 19:59:43 GMT
From: Clinton Bodine <Clinton.Bodine@mci.com>
Subject: Help unpacking Little-Endian shorts and longs
Message-Id: <351AB312.10CA9891@mci.com>
Hi All,
I'm an a DEC Alpha running Digital Unix 4.0 and Perl 5.003.
I'm trying to read a file with some binary data stored as short, short,
ulong etc. and the rest as characters. My program read()s the record into
memory, then substr() each field. When I try to
unpack("S*",$ushort_field), I get very odd data and I've realized the the
bytes are swapped.
I've tried several different templates, but none of them give me the
results I expect. If I reverse() the 2-byte string $ushort_field, then the
"S" template works. My input file was created on the same Alpha server
that my Perl script is running.
Shouldn't Perl be doing the right thing with these structures? Is there
something I could do that would do the right thing (or even be more
efficient?)
This code is how I read things right now, but I don't want to have to do
even weirder things for longs.
read(INFILE,$rec,290);
$ushort = join("",unpack("S*",reverse(substr($rec, 6, 2))));
print $ushort;
PS. My news server is no longer carrying perl.porters-gw. Did the group
disappear or is my news server admin being a pain? Does anyone have a
publicly accessible news server with this group?
--
Clinton Bodine
Email: Clinton.Bodine@mci.com
------------------------------
Date: Thu, 26 Mar 1998 19:37:08 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: Object destruction order non-deterministic?
Message-Id: <slrn6hlbgg.s26.jgloudon@manitoba.bbn.com>
Peter Scott <psf@euclid.jpl.nasa.gov> wrote:
>two objects were called. The code was essentially:
>
> { my $a = new A; foo(); }
> sub foo { my $b = new B; do_stuff; }
>
>yet A::DESTROY was called before B::DESTROY. I had (obviously
>incorrectly) assumed that the chain of events would be: $b goes out of
>scope when exiting sub foo, calls B::DESTROY; $a goes out of scope
>when exiting block in main program, calls A::DESTROY.
<- Other comments removed >
>
>(It turned out to be vexing in this case, because $a was an object wrapped
>around a DBI handle (so A::DESTROY called the disconnect method on the handle)
>and $b was an object I had wrapped around a DBI cursor (and B::DESTROY
>called the native cursor's finish method); destroying $a while a $b still
>existed caused DBI to complain about the extant cursor. I'll have to
>find another approach.)
If you run the following code with the # warn commented and uncommented you get
a different order of DESTROY calls. Perl apparently does some early destroy
calls. So there is determinism with some undocumented(?) optimizations.
The actual problem you are having is that you aren't using the object-oriented
techniques in quite the right way.
If $b needs to access something that is 'encapsulated' in $a, it should be
doing so _only_ via a method call. In order to call the method you have to pass
$a. Passing $a would have prevented it from being destroyed at the wrong time.
# Destructor sequence quirk code
package joe;
sub new { my $self = shift; my $copy = shift; bless \$copy, $self; }
sub DESTROY { warn "Destroying : ${$_[0]}\n"; }
package main;
&outer;
sub outer {
my $a = new joe('A');
inner();
# warn "no op\n";
}
sub inner { my $b = new joe('B'); &anotherone; }
sub anotherone { my $noop = 1; $noop; };
--
Jason Gloudon
------------------------------
Date: 26 Mar 1998 18:05:05 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Odd-Numbered Array to Hash
Message-Id: <6fe5ch$qp5@news-central.tiac.net>
In article <6fe2he$27a@fridge.shore.net>,
Art Cohen <upsetter@shore.net> wrote:
>Hi Folks;
>
>I have a list with an odd number of elements... let's say it looks like
>this:
>
> @data = ("name", "Art", "phone");
>
> (The reason for this is that the user left the phone number blank and it
> got written out to a data file as "name\tArt\tphone\t". When I later
> split on tab characters I got the above array).
If you know that there are going to be a specific number of elements then
@data = split /\t/, $line, 4;
might be what you need to avoid having the final null field ditched by
split.
check the split docs in perlfunc for the details of the LIMIT arg. to
split.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Thu, 26 Mar 1998 13:14:51 -0600
From: Patrick Timmins <ptimmins@netserv.unmc.edu>
Subject: Re: Odd-Numbered Array to Hash
Message-Id: <351AA92B.691D@netserv.unmc.edu>
You could take care of this with your handling of the form data before
it is ever written to the data file you're calling; eg, in the script
that parses your form data you could say something like:
if ($phone eq "") {$phone = "Not Available";}
This way $phone will contain whatever your user enters, or "Not
Available" if your user skips that field.
Hope that helps.
Patrick Timmins
U. Nebraska Medical Center
Art Cohen wrote:
>
> Hi Folks;
>
> I have a list with an odd number of elements... let's say it looks like
> this:
>
> @data = ("name", "Art", "phone");
>
> (The reason for this is that the user left the phone number blank and it
> got written out to a data file as "name\tArt\tphone\t". When I later
> split on tab characters I got the above array).
>
> I want to convert this to a hash %data where $data{'name'} eq "Art" and
> $data{'phone'} eq "", however, simply saying
>
> %data = @data;
>
> doesn't work... the last field ("phone") simply gets thrown into the bit
> bucket. Is there any way to avoid this?
>
> I can think of a number of ways to get around this (e.g. leave the newline
> at the end and then chomp each individual field) but they're all kind of
> kludgy... is there some easy or preferred way of doing this? I've checked
> the FAQ and man perldata but haven't found any clue.
>
> Thanks in advance.
>
> --Art
> (email cc preferred)
>
> National Ska/Reggae Calendar: www.ziplink.net/~upsetter/ska/calendar.html
> Boston Ska Home Page: www.ziplink.net/~upsetter/ska/index.html
------------------------------
Date: Thu, 26 Mar 1998 19:08:52 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Odd-Numbered Array to Hash
Message-Id: <351ba4a1.1814062@news.tornado.be>
Art Cohen wrote:
> @data = ("name", "Art", "phone");
>I want to convert this to a hash %data where $data{'name'} eq "Art" and
>$data{'phone'} eq "", however, simply saying
>
> %data = @data;
>
>doesn't work... the last field ("phone") simply gets thrown into the bit
>bucket. Is there any way to avoid this?
Well, add one element to the array if it has an odd number of elements.
This ought to work:
push @data,'' if @data & 1;
Yup, it looks like it does.
HTH,
Bart.
------------------------------
Date: 26 Mar 1998 19:02:00 GMT
From: Art Cohen <upsetter@shore.net>
Subject: Re: Odd-Numbered Array to Hash
Message-Id: <6fe8n8$99r@fridge.shore.net>
Craig Berry <cberry@cinenet.net> wrote:
: push @data, undef if @data % 2;
: %data = @data;
: I've used undef rather than an empty string for the missing value so you
: can distinguish missing from 'supplied but blank' values -- in case that
: ever matters.
This is basically what I wound up doing (although I used "" since I'm not
particularly concerned about whether the user intentionally left the field
blank). Mike Stok was also helpful enough to point out (in email) that I
can use a limit of -1 (on split) if I don't know the number of fields I'm
supposed to have, which will preserve the null field at the end.
--Art
National Ska/Reggae Calendar: www.ziplink.net/~upsetter/ska/calendar.html
Boston Ska Home Page: www.ziplink.net/~upsetter/ska/index.html
------------------------------
Date: Thu, 26 Mar 1998 10:54:44 -0800
From: "Benjamin Rosenthal" <benjamin@cgusa.com>
Subject: Perl Programmer needed in San Jose, CA
Message-Id: <6fe8ca$29r$1@toro.bais.com>
This is a contract and/or permanent position. Great startup company.
REQUIRED SKILLS:
* Mid-level Perl Programming experience (1-3 years); experience should
be mostly with Perl 5.x
* Understanding of how to build Perl interfaces to databases and work
with most popular databases
* Familiarity with HTML
* Experience in working in a team environment
* Understanding of corporate culture in a start-up business
* Responsible, highly motivated individual
PROJECT DATA:
* Development of Perl applications for the Web environment
* UNIX operating system/understanding of NT a plus
* Database normalization and basic schema development
* Complex CGI script development
DAY TO DAY DUTIES:
* Mostly programming and product development
* Weekly client contact
* Some product implementation
* Some training
WORKING ENVIRONMENT:
* On-site in downtown San Jose (near light-rail in the Software
Business Cluster)
* Great entrepreneurial exposure (fast-growing, start-up)
Send resumes to benjamin@cgusa.com ASAP.
****************************************************************************
Benjamin Rosenthal email: benjamin@cgusa.com
Carnaghe and Gibbs voice: (415) 956-6400 x20
Business Solutions, Inc fax: (415) 956-6450
------------------------------
Date: Thu, 26 Mar 1998 20:14:51 GMT
From: Andrew Kuchling <akuchlin@cnri.reston.va.us>
Subject: Re: Perl versus Python benchmark-results
Message-Id: <199803262014.PAA15588@newcnri.cnri.reston.va.us>
[Followups set to comp.lang.python]
Thomas Ackermann writes:
>My interest in this is simply to get a feeling for how fast Python is
>campared to Perl in some few areas (as choosen from a seemingly good
>perl-programmer). Personally this was sponsered by a friend's sentence
>about the apparent outcome: "Python has to grow two or three years to
>be able to beat Perl in regex-issues" - and i was satisfied to see that
>it *can* be faster in at least some cases.
Perl5.005, which is now heading for beta status, makes many
changes to the regex code, adding new features--lookbehinds being the
most notable--and various optimizations. Therefore PCRE is going to
need at least another go-round to add these new features.
It would be an interesting, and not completely trivial, task
to create a good regex benchmark suite. To do that, you'd have to
profile existing programs to see what kind of patterns are used, and
what strings they're applied to. For example, are most strings
single-line-sized (~80 characters) or are they larger, multiple-K
chunks of data?
>What still would be interesting for me is, if the Python-version *can* be
>coded to be faster for the first test (only one pattern) - just because
>perl is *such* faster there.
That's probably because of the "screamer" optimization in
Perl; it detects if there's some fixed substring that must be present
in any successful match, and looks for it. For example, if your
pattern is a{3,5}foo, it can determine that any match must be found
from 3 to 5 characters in front of the string "foo", and can do a fast
string search for foo, before backing up 5 characters and starting the
regex engine. Therefore, for a single fixed string, Perl is probably
close to string.find()'s speed, because that's all it's doing.
PCRE doesn't do this analysis yet, though it's on my list
(http://starship.skyport.net/crew/amk/regex/ for the full TODO list).
Another potential big win is to implement automatic insertion of cuts
(\X in PCRE, (?> in Perl5.005); if you're matching a*b, and the 'b'
fails, there's no need to backtrack at all, because anything that
matched 'a' can't possibly match 'b'.
A while back I started a mailing list to discuss further PCRE
development, though it's gotten no traffic yet because I haven't
gotten back to regexes. Feel feel to join by going to
http://www.findmail.com/listsaver/pcre-devel/ . Maybe in another
month or two I'll get around to regex development again.
A.M. Kuchling http://starship.skyport.net/crew/amk/
I cannot imagine any boy of spirit who would not be delighted to play a
drunkard---even to vomiting---in front of his Sunday school. Indeed, the
vomiting might be the chief attraction of the role.
-- Robertson Davies, "Forgotten Dialogues"
------------------------------
Date: Thu, 26 Mar 1998 11:57:43 -0600
From: Ken Chesak <ken.chesak@dhs.state.tx.us>
Subject: Perl5 DBLIB RPC
Message-Id: <351A9717.315FF6BA@dhs.state.tx.us>
I need an example of executing an RPC(stored procedure) with 1 input
parameter and 1 output parameter. I know the basic calls are dbrpcinit,
dbrpcparam, dbrpcsend, dbresults. The RPC is only called once so a
little overhead is not an issue. Can this be done without using all 4
calls mentioned above.
I am running Perl5.004_01, using the DBLIB calls version 2.04 on HP
Unix.
Thanks
------------------------------
Date: 26 Mar 1998 11:32:44 -0600
From: tye@fiinix.metronet.com (Tye McQueen)
Subject: Re: PerlRing???
Message-Id: <6fe3ft$54c@fiinix.metronet.com>
Gellyfish@btinternet.com (Jonathan Stowe) writes:
) With the GSAR binary distribution there is a program "tkpod.bat" that
) displays pods in a nice(?) wndow. It could be possible to associate
) that script with the .POD extension and then those afflicted with
) Win32 could simply double click the pod files in Explorer or whatever.
Or put a help.html file in the root of the perl directory tree
with links to the html-ized documentation. Moving the html-ized
documentation into perl/doc instead of being burried under
perl/lib/pod/html would help even more. You can justify this
by asserting that web browsers are bocoming very common even on
platforms where they didn't used to be. Or you can justify it by
asserting that the throngs of Microsoft customers are the worst at
finding the documentation and so they need extra help, especially
since they have the greatest potential for flooding the perl
resources with silly questions. Depends on your point of view.
If we also make the links between the html files use relative
paths (at least by default on Microsoft platforms), then these
html docs will be usable even if they reside on a shared network
drive, a web server, or just get moved or installed in other
than the directory in which they were generated.
Comments?
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
------------------------------
Date: Thu, 26 Mar 1998 11:04:42 -0700
From: "Richard W. Koehler" <rkoehler@osmre.gov>
Subject: Re: PROPOSAL: The Perl Dictionary
Message-Id: <6fe5eb$9bn@gargantubrain.osmre.gov>
Some possible new definitions for the Perl Dictionary:
perlambulate \perl-'am-byu-late\ vb.: to take a stroll through Perl,
preferably with certain
perlferred animals (camels, llamas, geckos), especially via the keyboard, as
opposed to
on foot, which tends to damage things.
perlfervid \(,)perl-'fer-vid\, adj.: 1. marked by overwrought or exaggerated
emotion when
responding to posts in comp.lang.perl.misc, especially when a newbie didn't
first consult
the Camel, the Llama, the Gecko, the Panther, the FAQ, perldoc, the entire
body of C
source code, every document in the archives, and/or the author's thoughts
when they were
writing modules <Al wrote with ~ vigor concerning the newbie's question on
the proper
usage of @_ when munging globs> 2. the kind of reponse this post will
generate.
perlfidy \'perl-fed-e\, n.: the act of writing code in Java (gasp) <the
source code to the
applet convinced the jury of Bill's obvious ~>.
Rick Koehler, print "JA-pilgrim-on-the-path-to-Perldom\n"; # Lost in the
Wilderness
------------------------------
Date: 26 Mar 1998 18:04:49 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: regular expression
Message-Id: <6fe5c1$8ib$2@marina.cinenet.net>
John Porter (jdporter@min.net) wrote:
: Craig Berry wrote:
: >
: > 8($J$Z6!*:2VE]$} (NortonNg.bbs@CHS.Dorm10.NCTU.edu.tw) wrote:
: > : just a simple question: how can I write a perl script to identify
: > : all strings of 0's and 1's that do not contain the substring 011 ?
:
: Hope the kid gets an A for your work.
Heck, I was feeling generous -- but you're right, I should have spotted
this as a homework post rather than getting sucked into spoon-feeding him
an answer. In any case, unless he ends up understanding my solutions,
that A won't do him any good in the long run.
---------------------------------------------------------------------
| 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: Thu, 26 Mar 1998 11:27:57 -0600
From: John Lukas <jalukas@lucent.com>
To: Jim Stern <jstern@world.northgrum.com>
Subject: Re: removing eval from a loop
Message-Id: <351A901D.7857@lucent.com>
Jim -
Thanks for your reply. If I may, a couple followup questions:
> The bad news: BLOCK eval is not flexible enough for your needs. It
> requires that "the code to be executed doesn't vary." (See perlfunc.)
I don't think that I understand. The code (within the eval) doesn't
vary,
at least for any given invocation of the program. That is, the string of
variables that the input record is to be split into is determined at the
beginning of the invocation, and does not change. The functionality that
I was looking for with eval is analagous to the "o" modifier of the
search
operator. I'm not sure if this means that the code varies (in this
context)
or not.
> @hash{@ARatts} = split /${delim}/, $_;
OK, I understand that. Then, to reference the carodnr field, I use
$hash{carodnr}, correct? At least this seems to work the way I expect.
> print "@hash{@ARatts}\n";
This I could not get to work. It puts spaces between fields, rather than
the desired "$," (in this case, a pipe). I tried:
print @hash{@ARatts} . "\n";
which I thought would be the same as:
print $hash{carodnr}, $hash{field}, $hash{order}, $hash{actdate},
$hash{value} . "\n";
(which is the effect I want) but instead, it acted like:
print $hash{value} . "\n";
(that is, it printed the value of the last field, unfortunately named
"value")
which I don't understand.
TIA.
--
John Lukas
630-224-6290
jalukas@lucent.com
------------------------------
Date: 26 Mar 1998 19:23:02 GMT
From: tsatan@hotmail.com
Subject: ts: why have "push" and "unshift"?
Message-Id: <6fe9um$g30$1@orthanc.reference.com>
Why does perl have the "push" and "unshift" functions?
Consider an array: @nums = (1, 2, 3);
Then: push @nums, 4; is the same as @nums= (@nums, 4);
and: unshift @nums, 0; is the same as @nums= (0, @nums);
I know perl's motto is "There's more than one way to do it",
but these two functions seem especially unnecessary. Are they
more efficient? Or am I missing a case where the second solution
would fail?
ps. Thanks Quentin && Randal for answering my last question!
--------------------------------------------------------------------
Posted using Reference.COM http://WWW.Reference.COM
FREE Usenet and Mailing list archive, directory and clipping service
--------------------------------------------------------------------
------------------------------
Date: 26 Mar 1998 21:41:05 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: ts: why have "push" and "unshift"?
Message-Id: <oeed8f92qb2.fsf@alpha.hut.fi>
tsatan@hotmail.com writes:
>
> Why does perl have the "push" and "unshift" functions?
> Consider an array: @nums = (1, 2, 3);
> Then: push @nums, 4; is the same as @nums= (@nums, 4);
> and: unshift @nums, 0; is the same as @nums= (0, @nums);
The assignment versions do each an unnecessary copy (and a list
creation). push() and unshift() operate the array in-place which
is much faster.
Watch:
use Benchmark;
@a = 1..10;
timethese(100000, {
'a' => '@a=1..10',
'b' => '@a=1..10;push(@a, 11)',
'c' => '@a=1..10;@a=(@a,11)'
});
gives in my machine:
Benchmark: timing 100000 iterations of a, b, c...
a: 3 secs ( 3.37 usr 0.00 sys = 3.37 cpu)
b: 4 secs ( 3.77 usr 0.00 sys = 3.77 cpu)
c: 8 secs ( 7.18 usr 0.05 sys = 7.23 cpu)
which means that it can do 250k (100k/(3.37-3.37)) pushes in one
second to a 10-element list but only 26k (100k/(7.23-3.37))
"list-appends" in one second. A ten-fold speed difference is not to
be sneered at.
It gets only worse if the array is longer, for @a=1..20:
Benchmark: timing 100000 iterations of a, b, c...
a: 7 secs ( 6.25 usr 0.03 sys = 6.28 cpu)
b: 7 secs ( 6.62 usr 0.00 sys = 6.62 cpu)
c: 13 secs (12.72 usr 0.05 sys = 12.77 cpu)
which ends up as 294k vs 15k, almost a 20-fold speed difference.
> I know perl's motto is "There's more than one way to do it",
> but these two functions seem especially unnecessary. Are they
Blasphemy! :-)
> more efficient? Or am I missing a case where the second solution
> would fail?
>
> ps. Thanks Quentin && Randal for answering my last question!
>
>
> --------------------------------------------------------------------
> Posted using Reference.COM http://WWW.Reference.COM
> FREE Usenet and Mailing list archive, directory and clipping service
> --------------------------------------------------------------------
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Thu, 26 Mar 1998 12:29:56 -0500
From: Kelly Bond <kab@mail.utexas.edu>
Subject: using quot in Net::FTP to chmod
Message-Id: <351A908E.46D2C344@mail.utexas.edu>
I've got a little script that FTPs files around various machines.
After I do the ftp, I need to set file permissions and I thought I could do
that like this:
$ftp->quot('chmod',755,$filename)
but this doens't work and I get:
'CHMOD 700 /path/to/file/filename.txt': command not understood
in $ftp->message()
Now I know I can issue this command from the command line in the ftp program
and it works just fine, so I'm assuming I'm messing up the quot part of the
code (which I am totally unfamiliar with).
What am I doing wrong?
Thanks,
Kelly Bond
kab@mail.utexas.edu
ACS - UT Austin
------------------------------
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 2188
**************************************