[7435] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1060 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 22 20:17:14 1997

Date: Mon, 22 Sep 97 17:00:31 -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, 22 Sep 1997     Volume: 8 Number: 1060

Today's topics:
     Re: Any Recommendations for portable signal processing? (Ilya Zakharevich)
     Re: Any Recommendations for portable signal processing? (Adrian Pepper)
     Re: arithmetics on multiple array? <rootbeer@teleport.com>
     Re: arithmetics on multiple array? (Andrew M. Langmead)
     Re: bitwise xor of strings <rootbeer@teleport.com>
     CONTRACT WORK FOR PERL PROGRAMER <John.R.Law@btinternet.com>
     Looking for Freelancer? (Rick B Teh)
     Re: Memory leak? <NerveGas@nospam.inconnect.com>
     ODBC Error -5005 <mreahm@raex.com>
     Re: Perl <=> C Server (dave)
     Perl Framework for Reusable Web Components <gberche@acm.org>
     Re: Perl, NT, and relational databases <westxga@ptsc.slg.eds.com>
     Re: Perl, NT, and relational databases <rmaillet@inigo.us.dg.com>
     Re: Perl, NT, and relational databases <rmaillet@inigo.us.dg.com>
     Printing perl - Win'95 (Lynn. Rickards)
     Regular Expressions <scott.cullen@creativeloafing.com>
     Re: Ret Value from Opened Pipe <jadestar@rahul.net>
     Re: Ret Value from Opened Pipe (Matthew Cravit)
     Re: Statistics for comp.lang.perl.misc <fishrman@shell.wco.com>
     symbolic dereferencing of my() variables -- can it be d (Rahul Dhesi)
     test <John.R.Law@btinternet.com>
     Re: test (Jeremy D. Zawodny)
     Where is perl/Tk for Win32 (Weihan Chang)
     where's the latest version of jcode.pl (Neil Bowers)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 22 Sep 1997 21:25:37 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Any Recommendations for portable signal processing?
Message-Id: <606noh$8k1@agate.berkeley.edu>

In article <606g0q$jtf$1@news1.atlantic.net>,
Chip Salzenberg <chip@pobox.com> wrote:
> >arpepper@math.uwaterloo.ca (Adrian Pepper) writes:
> >>keys %SIG
> >>is not initialized to anything.  Nor is there a built-in "kill -l".
> 
> It's for performance reasons.  But I think that specific case should be
> changed (i.e. C<keys %SIG> should populate %SIG).

I think it is for lazyness reasons, not for performance.  Nobody had
time to test with -DDYNAMIC_ENV_FETCH under *nixish systems.  It
should (?) work correctly under VMS *now*.

Ilya


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

Date: Mon, 22 Sep 1997 16:19:39 GMT
From: arpepper@math.uwaterloo.ca (Adrian Pepper)
Subject: Re: Any Recommendations for portable signal processing?
Message-Id: <EGx40r.oMq@undergrad.math.uwaterloo.ca>

aml@world.std.com (Andrew M. Langmead) wrote,
 in article <EGuErw.F55@world.std.com>:
>arpepper@math.uwaterloo.ca (Adrian Pepper) writes:
>
>>if I decide to temporarily catch something for
>>some reasons, how do I decide whether to put it back to DEFAULT or
>>IGNORE?
>
>You can do something like this:
>
>  {
>     local($SIG{$signame}) = 'sig_catcher';
>     # do something
>  }  # end of block, localized va is gone, sig is reset to its original state.

Yes, of course.  Thankyou.

My mistake was in thinking of the signal catchers as necessarily global
(I wonder why).  Obviously perl catches all signals, and looks around
for things to do with them.  Presumably it is careful when no user
function is associated with the signal to ignore (do nothing) or
emulate SIG_DFL depending upon the initial value it found for that
signal.  I'll get up the courage to go looking at the source one of
these days.  Hmm.  Looks like a targrep might be useful though for
that, though.

cat $DIR/latest.tar | tar xvf - `targrep -i -l signal $DIR/latest.tar`


There must be such a beast.  Locating or writing such a thing might
be a good way to avoid things I'm supposed to be doing.  8-)

My all-knowing boss had not heard of such a thing.

Hmm.  Archie seems to find a tgrep.  But it's too small to be that.
No, seems to be "tiny grep".

Hey.  I just got another guy here interested.  "Should be pretty
easy".  Paragraph mode.  Slurp?  Well, whenever the first of us "gets
some spare time".

What's the correct name for it?  Hmm.  Might want a -z (gzip) option too.

Although:

zcat $DIR/latest.tar.gz | tar xvf - `zcat $DIR/latest.tar.gz | targrep -i -l signal`

There must be such a beast.  Or maybe lots of such beasts.


Adrian Pepper
University of Waterloo.


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

Date: Mon, 22 Sep 1997 15:03:49 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: ahmed bentiba <beahmed@dartmouth.ccfne.ns.ca>
Subject: Re: arithmetics on multiple array?
Message-Id: <Pine.GSO.3.96.970922150215.3409I-100000@usertest.teleport.com>

On Mon, 22 Sep 1997, ahmed bentiba wrote:

> I would like to know if here is a perl script that allows me to do
> arithmetics on a text file (database) generated by another perl script?

There are lots of scripts which can do that. The one which you want may
not have been written yet, however. :-)  

If there's a module which does what you want, it should be listed in
the module list on CPAN. If you don't find one to your liking, you're
welcome and encouraged to submit one! :-)  

    http://www.perl.org/CPAN/
    http://www.perl.com/CPAN/

If you're wanting to do math on large arrays of numbers, I encourage you
to check out PDL. 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: Mon, 22 Sep 1997 22:34:52 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: arithmetics on multiple array?
Message-Id: <EGxLE5.89J@world.std.com>

ahmed bentiba <beahmed@dartmouth.ccfne.ns.ca> writes:

>john    5   6   7   8
>lisa      6   8  5    6
>carlos  5   5  9    6
>lee       8   5  6    4
> the first column holds names and the other columns hold numbers.
>I would like to sum, average...these columns.
>Is it possible in Perl? How?

Read the data. use the split operator to separate the data. Store the
results in arrays. Sum, average, ... the arrays.

while(<>) {
  ($name, @scores) = split ' ';
  for($elem = 0; $elem < scalar @scores; $elem++) {
      $sum[$elem] += $scores[$elem];
  }
  $no_records++;
}

for($elem = 0; $elem < scalar @sum; $elem++) {
   $average[$elem] = $sum[$elem]/$no_records;
}

print "@sum\n";
print "@average\n";

If there is some sort of mathimatical calculation that you need all of
the records in memory at once, then look into perl's implementation of
multidimensional arrays, as explained in the perlref, perllol, and
perldsc man pages:


while(<>) {
  ($name, @scores) = split ' ';
  $records{$name} = [ @scores ];
}










-- 
Andrew Langmead


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

Date: Mon, 22 Sep 1997 15:01:19 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jim Michael <jim.michael@gecm.com>
Subject: Re: bitwise xor of strings
Message-Id: <Pine.GSO.3.96.970922150024.3409H-100000@usertest.teleport.com>

On Mon, 22 Sep 1997, Jim Michael wrote:

> Tom Phoenix wrote:
> > 
> >     sub dumphex {
> >         print join(" ", map unpack("H*", $_), @_), "\n";
> >     }
> >     $b = "0101";
> >     $c = "0011";
> >     dumphex $b ^ $c;
> 
> From which I get the interesting result: 
> 
> 00010100

Surprised? You wouldn't be if you'd read the rest of my message, in which
I said "Perl is xoring the hex values 30313031 and 30303131 to get the hex
value 00010100, a four byte string". 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: 22 Sep 1997 19:17:34 GMT
From: "John Law" <John.R.Law@btinternet.com>
Subject: CONTRACT WORK FOR PERL PROGRAMER
Message-Id: <01bcc78c$515f9a20$LocalHost@default>

We are a small company developing a website for 
international food trading.
The address is www.acefoods.com where you can 
see the early stages of constuction.
The site is planned to be very interactive.
Our present programer is coming unstuck on the perl script.
 We are looking to get a quote by someone experienced 
in perl to complete the work that has begun. 
If you or anyone you know is interested please e-mail me
at johnlaw@acefoods.com

 


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

Date: 22 Sep 1997 19:33:37 GMT
From: boonteh@acsu.buffalo.edu (Rick B Teh)
Subject: Looking for Freelancer?
Message-Id: <606h6h$qup$1@prometheus.acsu.buffalo.edu>

Hi,

I'm interested in doing freelance work of any kind (web related).
- Web Design, Java, CGI(Perl), Database Integration, Graphics Design, ASP.
- curretly playing with ActiveX

To find out more about me, goto http://www.panix.com/~rickteh

-Rick          


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

Date: Mon, 22 Sep 1997 16:35:32 -0600
From: Steve Wolfe <NerveGas@nospam.inconnect.com>
Subject: Re: Memory leak?
Message-Id: <3426F2B4.7ABA@nospam.inconnect.com>

Jason Gloudon wrote:
> 
>         I am curious are we acknowledging the presence of a memory leak here >or
> can someone explain if the code we were shown explains the memory usage.
> As it is I can't explain the memory usage.

     There was definitely something funky going on with the original
code, to eat up over 250 megs, so I re-wrote the program from start,
using a little more common sense this time, and doing all of the
splitting and array-reading at the start, instead of in the
zillion-iteration loop, so that the same function isn't performed a
million times, and the memory footprint increased about 5K over apprx. 8
million iterations, so that solved my immediate problem.

    As to whether there is a bona-fide memory leak, I decided to just
use a high-itaration loop with the split() function and variable
re-assignment to test it, and ran it through 10,000,000 iterations, and
the memory stayed stable, so I think it was just crappy coding on my
part.

> Also to the original poster there is no such group as comp.lang.perl anymore.

     I just read 13 messages in it today - your news feed must not carry
it.  Talk to your admin, and they can probably add it for you, if the
feed that they get carries it.

Steve Wolfe


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

Date: Mon, 22 Sep 1997 18:15:57 -0400
From: "Melissa L. Reahm" <mreahm@raex.com>
Subject: ODBC Error -5005
Message-Id: <3426EE1D.569BE1FD@raex.com>

Hello:

I am trying to connect to an Excel spreadsheet using Perl Win32::ODBC
extensions.  On testing the connection, the error

[Microsoft][ODBC Excel Driver] Couldn't decrypt file.

An error number of -5005 is also given.

If anybody can give any ideas on how to solve this, I would greatly
appreciate it.

Please E-mail replies to

mreahm@raex.com

Thanks,
Melissa




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

Date: Mon, 22 Sep 1997 20:54:10 GMT
From: over@the.net (dave)
Subject: Re: Perl <=> C Server
Message-Id: <3426d961.533321@news.one.net>

Gary Howland <ghowland@hotlava.com> wrote:

>Gary Mui wrote:
>> 
>> Is it possible to have a perl program talk to a server written
>> in C that reads and writes normal C structures (as opposed
>> to parseable text)?
>
>Sure it us.  Use 'pack'.  I've used it to talk RPC, SNMP, NFS
>and dozens of other things.  Check out modules like Net::DNS,
>along with some of the stuff at http://www.hotlava.com/software/
>
>Gary

Need to be clear about one thing.  Perl does not see strings as being
terminated with '\0'  like C does.  This makes things kinda easier
when sending from Perl to C, since Perl can easily concatenate strings
with '\0' used as a separator.  But it makes things a little harder
sending from C to Perl, since you will probably need to send a length
value for a string, then unpack the length value, then unpack the
string.


Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________


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

Date: Tue, 23 Sep 1997 00:08:44 -0700
From: guillaume berche <gberche@acm.org>
Subject: Perl Framework for Reusable Web Components
Message-Id: <34276AFC.563A@acm.org>

Hi,

Following is the abstract of a paper I wrote about a perl framework to
visually build web sites. It would use perl, apache, and other public
domain tools. I hope it can be interesting to some perl developpers.

Sincerely,

Guillaume Berche


+----------------------------------------------------------


Perl Framework for Reusable Web Components

Guillaume Berche. July 28, 1997.
gberche@acm.org


I. Introduction


This short paper briefly describes an Object-Oriented perl framework
designed to visually build dynamic web sites from a set of reusable
components. It is intended at web masters, and web developers.

The goal of this paper is to present the framework, and get feedback
from the potential users. If you are interested by this framework,
please DO PROVIDE FEEDBACK by sending email at gberche@acm.org



II. What I miss from the current public domain web development tools.


Lots of great software products are available in the public domain, and
perform very well their tasks in their specific domains (Perl and its
CPAN, Apache, RDBMS.)
However, while being independently very good products, these public
domain packages can not easily be used out-of-the-box to quickly develop
professional web applications because the learning and administration
overhead associated with each product adds-up.

Here is what I really miss as a web-master and a web application
developer:

* Reusability
Reusable web-specific components.
* Integrated solution
An integrated API which isolates the web developers from the complexity
of each associated products.
* Flexibility
Being able to modify the data model without changing the associated
logic code. 
* Non Programmer support: 
Visually build a web application using a web user interface.



III. Framework concepts


To provide the necessary flexibility to changes inherent to the web
domain, a mechanism of visual component configuration has been designed.
The following vocabulary describes the different "objects" found in the
system.
* Components are reusable perl packages implementing web behaviors (e.g.
a generic HTML table). They are created at development time by writing
code.
* Templates are instances of components, which contain a configuration
state specified at design-time using a standard web, interface (e.g. a
customer formatted as an HTML table).
* Objects are instances of templates, which hold a data state (e.g. the
customer "John Foo"). They are instanciated at run-time.

1. Development time

Analyzing dynamic web pages shows that a typical page contains a
composite entity made of basic CGI input fields, and some kind of
associated logic to handle its selection/consultation/edition. This
analysis lead to a decomposition of components into three cohesive kinds
which enhance reusability and extensibility:
* Field components: Atomic-data type (text field, check box, popup, but
also server-side and client-side validated data: URL, GIF picture, Zip
code ...)
* Composite components: Handles printing and edition of an aggregate of
fields using a specific look and feel ( e.g. HTML table, freeform
object, client-side validated form ... ) 
* Container components: Selects and formats one or more composites
object (e.g. indexes, search panels, multi-frame indexes ... )

The component_registry keeps track of all the available components in
the system.
The newly developed components inherit from base components that provide
base functionality.

2. Design time

At design-time, templates are created by configuring instances of
components using a standard web interface:
* Field template: An atomic data widget (e.g. a customer name text
field, a corporation pop up, a customer logo widget)
* Composite template: An aggregate of field templates with a specific
printing and editing aspect (a customer whose fields printed in an HTML
table with two columns: label and widget, and one row by field object)
* Container template: Provides a way to select a composite object (e.g.
a index of customer, in which the index field is the customer name)

Designing a web site is done through modeling the site data-structure by
creating templates (i.e. configuring components.) Each component
provides methods that generate the HTML code and handle CGI requests to
enable the web master to configure its behavior using a standard web
interface. Once a template has been created, its configuration state is
serialized into a string, which is saved in a database. 

The model_builder keeps track of all the available templates in the
system, and coordinates web interface to create templates.
The DB_manager handles all the interactions with the database. It saves
the templates' serialized state in the database, and updates the
structure of the database storage tables appropriately. 

3. Run Time

At run-time, instances of templates are created by accessing the
database storage tables:
* Field object: a web widget containing an atomic value which knows how
to generate the HTML code to display itself and be edited (e.g. "John
Foo" is the value stored in a customer text field).
* Composite object: an aggregate of field objects with a specific
look-and-feel (e.g. an HTML table filled with the customer data: name,
corporation and logotype.)
* Container object: a selector of composite objects (e.g. an index which
displays 30 customer names linked to their full customer display, and
provides navigation access to the previous/next 30 ones)

Each composite object data state is stored in a row of a database table
associated with the corresponding composite template. Each row contains
the serialized data state of the associated field object. For example
the customer objects will be stored in the customer template table
displayed below:

+---+---------------+-------------+------------+
| ID| Customer Name | Corporation | Logotype   |
+---+---------------+-------------+------------+
| 1 | John Foo      | Foo Corp.   | img004.gif |
+---+---------------+-------------+------------+
| 2 | Jane Bar      | Bar Corp.   | img005.gif |
+---+---------------+-------------+------------+

Special tags embedded into static HTML pages invoke container objects.
The SSI_mgr (Server-Side-Include manager), parses these tags, and
compile the invocations to optimize performance. 
The object_registry keeps track of available templates and, when
requested, constructs the ones that had never been instanciated by
retrieving their serialized state.
Each container object instanciates its contained composite objects by
requesting their serialized state to the DB_manager. Container objects
when edited update their stored state using the same mechanism.
Before any object is displayed or edited, the end-user is authenticated,
is checked against the object's access control list by the security_mgr.


IV. What does the framework offer?



The ultimate goal of this framework is to enable web masters to build
dynamic web sites in hours by visually configuring a set of reusable
components.


1. Fit the needs of web masters

To web masters, the framework tries to provide the following approach to
web site design:
* Visual Web design: To develop its web site (e.g. an on-line store) the
web master simply models its data using a standard web interface. He
configures ready-to-use standard web components (containers, composite
objects, and fields) to publish rich dynamic content. The framework
handles all the necessary logic, security checking, and database
queries. 
* Integration with existing environment: The web master keeps using its
favorite HTML editor to design the look-and-feel of its site, and simply
adds invocations to server-side web objects who handle all the
associated logic to provide dynamic content.
* Dynamic web site configuration: The web site data model can easily be
modified without requiring any compilation, or manual database updating.
The administration tasks and the necessary technical knowledge are kept
minimal. Also new reusable components can seamlessly by plugged-in to
provide new functionality.

2. Fit the needs of web developers

The framework tries to provide programmers who build reusable web
components with an easy-to-use API with the following support:
* Design-time configuration handling: While developing a new web
component, the web developer can rely on the framework to provide a
default configuration web interface for it.
* Dynamic data model management: The web site publishes dynamic data
that will be stored in a database. The web master visually models its
data, and the database model will be updated appropriately. Changing the
data published does not imply any code change. 
* Database management: The framework handles the persistency of the
dynamic content as well as the configuration data specified at design
time. Consequently, web developers are isolated from the storage
mechanism, and can concentrate on developing web-specific code.
* Security handling: The framework can automatically perform user
authentication, and check incoming requests against the associated
object's access control list.
* Latest web-technology support: in-process CGI, DBI connectors, HTML
embedded server-side object invocation, support for client-side
components ...


V. How to learn more about the framework?


A draft document of the framework design is to be available at
http://wwwperso.hol.fr/~gberche/. This document explains design
decisions and provides a draft version of a possible API. Also a small
preliminary prototype illustrates the concept of visual web site
construction.
Please send email at gberche@acm.org if you have troubles getting this
software or if you are interested by this framework.


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

Date: Mon, 22 Sep 1997 10:07:12 +0000
From: Glenn West <westxga@ptsc.slg.eds.com>
Subject: Re: Perl, NT, and relational databases
Message-Id: <34264350.F4D@ptsc.slg.eds.com>

Robert L'Estange wrote:
> 
> Hi
> 
> I'm currently running a bunch of CGI scripts on NT.  The CGI scripts are
> written in Visual Basic and are used primarily to store and retrieve
> information to and from an Access database.   Upon deciding to learn to
> write CGI scripts with Perl (so that I wasn't tied to NT with my VB), I
> thought I might start my Perl education by rewriting some of my VB CGI in
> Perl.  I took my first look at some Perl literature today ("Learning Perl"
> I think it was called, written by the Perl author) and Perl looks very easy
> to learn and use; particularly with the help of CGI.pm.  The one thing I
> couldn't find info on however was how to interact with relational databases
> like Access.
> 
> My question: Can Perl be used on NT to store data to and retrieve data from
> an Access database with the use of SQL queries (or any other method I
> guess)?

check out www.perl.com

> 
> Thanks
> Rob
> 
> PS. Off-topic but...  are there any relational database products that can
> be used on UNIX?

How about Oracle, Ingres, Sybase and Informix for starters?


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

Date: Mon, 22 Sep 1997 17:11:12 -0400
From: Bob Maillet <rmaillet@inigo.us.dg.com>
To: Robert L'Estange <strangie@mailbox.uq.edu.au>
Subject: Re: Perl, NT, and relational databases
Message-Id: <3426DEEF.9D4A885F@inigo.us.dg.com>

> Can Perl be used on NT to store data to and retrieve data from
> an Access database with the use of SQL queries (or any other method I
> guess)?



Yes, if you are using perl5 for win32 you can download the perl module
Win32::ODBC  at:

http://www.roth.net/odbc/odbcfaq.htm

its good stuff.

Bob



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

Date: Mon, 22 Sep 1997 17:12:21 -0400
From: Bob Maillet <rmaillet@inigo.us.dg.com>
To: Robert L'Estange <strangie@mailbox.uq.edu.au>
Subject: Re: Perl, NT, and relational databases
Message-Id: <3426DF35.524F58C3@inigo.us.dg.com>

> Can Perl be used on NT to store data to and retrieve data from
> an Access database with the use of SQL queries (or any other method I
> guess)?



Yes, if you are using perl5 for win32 you can download the perl module
Win32::ODBC  at:

http://www.roth.net/odbc/odbcfaq.htm

its good stuff.

Bob



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

Date: Tue, 23 Sep 97 04:12:54 GMT
From: lynnr@lynn.softnet.co.uk (Lynn. Rickards)
Subject: Printing perl - Win'95
Message-Id: <N.092297.211255.05@n192p2i213.c3r4.pol.co.uk>

Greetings,

This question arises out of my recent usage of Gurusamy Sarathy's
excellent Win95/NT port of perl/TK... but I guess this is more
a perl question:

Printing under perl/unix (for my needs, anyway) is easy:

open PRINTER, "| cat  | lpr -h 2>/dev/null" or die "no printer: $!";
print PRINTER $stuff_to_print;

How do you achieve this under Win95? Printer selection would be nice,
too - the default printer on my own '95 machine is an A1 plotter,
so I'd like to be able to choose a more sensible alternative....

TIA

Lynn. Rickards
lynn@kam.com




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

Date: Mon, 22 Sep 1997 18:32:18 -0400
From: Scott Cullen <scott.cullen@creativeloafing.com>
Subject: Regular Expressions
Message-Id: <3426F1F2.B95@creativeloafing.com>

I am having some trouble with doing some pattern matching using regular
expressions and I was wondering if someone might be able to help. Thi
seems like it should be a simple process, but here's the problem...

I have some lines of HTML that always begin with a <P> and a <B> tag.
These tags are then followed by a couple of words, then the next line is
always a single word. It look like this:

<P><B>Arts & Entertainment
Clemson

I need to add a <BR> tag after Entertainment (which I have already
done). My problem is I also need to add a <BR> tag after Clemson. I'm
having trouble using Perl's Regex to, in layman's terms, "always put a
<BR> after the last word on the next line after a line that begins with
a <P><B> tag.

	Any help would be appreciated.
Thanks, -Scott
-- 
Scott Cullen
Online Technician
Eason Publications, Inc.
http://www.creativeloafing.com


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

Date: 22 Sep 1997 20:35:13 GMT
From: Jim Dennis <jadestar@rahul.net>
Subject: Re: Ret Value from Opened Pipe
Message-Id: <606kq2$a3m$1@samba.rahul.net>

Doug Seay (seay@absyss.fr) wrote:
: Jim Dennis wrote:
:>  How do I get the value returned by my open()'d process?
:>  Given code like:
:>       open (PROG, "|$myprog");
:>             print PROG "some input";
:>             print PROG "some more input";
:>       #???
:>       close(PROG);
:>       print $?;  #???
:> 
:>  My program is supposed to take to lines of input --
:>  and return one of several possible values.  I want
:>  my perl code to be able to distinguish between them,
:>  and act accordingly.

: Do you mean that the program named in $myprog is supposed to exchange
: input and output with this code snippet?  If so, never forget about the
: deadlocks.  Look at perlipc and IPC::Open2() for something that might do
: what you want.  

	No.  I don't want bidirectional communications between them.
	I want to shove values in, and get a return value (errorlevel).
	I don't need to read any data back.

:>         What I currently get is either 0 or 256 -- where I program
:>         is returning 0, 1, 255, 254, or 253 for various test
:>         cases.
: >
:>         Why doesn't this work as one would expect?

: If you just want return codes, I don't see any problems.  Here is my
: test case and the little exiting program ($myprog in your example).  Try
: playing with this and see what results you get.

: - doug

: --- results ---

: ~/bin> e
: result=0 (0) (0)
: result=4352 (0) (17)
: ~/bin> 

: --- main code ---  "e" ---

: #!/usr/local/bin/perl -w
: use strict;

: sub exiter(@)
: {
: open(P, "| exiter") || die "open() failed: $!\n";
: print P @_;
: close(P);
: my $rsig = $? % 256;
: my $rexit = ($?/256) % 256;
: printf "result=%d (%d) (%d)\n", $?, $rsig, $rexit;
: }

	What's all this % 256 stuff?  
	Why do you have an rsig and an rexit?
	
	Does standard Unix (Linux) use 16 or 32 bit return values?
	My tests with shell scripts suggests that it returns 
	modulo 256 of whatever you supply for a exit value?

	Example:
		#! /bin/bash
		#  	err
		exit $1

		$ err 250 ; echo $?
		250
		$ err 513 ; echo $?
		1
		$ err 512 ; echo $?
		0

	So, are you forced to extract the one character (byte) exit
	value from some other perl representation?  If so, where is
	this documented?

: exiter("0\n");
: exiter("17\n");

: --- child process --- "exiter" ---
:  
: #!/usr/local/bin/perl -w
: use strict;
: my $num = <STDIN>;
: exit int($num);

	Thanks, I'll forward this example along to my wife -- who
	was actually the one fighting with this code.

--
Jim Dennis,
Starshine Technical Services


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

Date: 22 Sep 1997 15:23:26 -0700
From: mcravit@best.com (Matthew Cravit)
Subject: Re: Ret Value from Opened Pipe
Message-Id: <606r4u$3as$1@shell3.ba.best.com>

In article <606kq2$a3m$1@samba.rahul.net>,
Jim Dennis  <jadestar@rahul.net> wrote:

>	What's all this % 256 stuff?  
>
>   [Snip]
> 
>	So, are you forced to extract the one character (byte) exit
>	value from some other perl representation?  If so, where is
>	this documented?

>From the perlfunc man page:

          The return value is the exit status of the program as returned 
          by the wait() call.  To get the actual exit value divide by 256.

If you read the man page for wait(2), you'll find the following about the
return value of wait() (at least, on Solaris; YMMV on other OSs):

         If the child process stopped, the high order 8 bits  of
         status  will  contain  the  number  of  the signal that
         caused the process to stop and the  low  order  8  bits
         will be set equal to WSTOPFLG.

         If the child process terminated due to an _exit() call,
         the  low  order 8 bits of status will be 0 and the high
         order 8 bits will contain the low order 8 bits  of  the
         argument  that the child process passed to _exit(); see
         exit(2).

         If the child process terminated due to  a  signal,  the
         high order 8 bits of status will be 0 and the low order
         8 bits will contain  the  number  of  the  signal  that
         caused  the  termination.  In  addition, if WCOREFLG is
         set, a  "core  image"  will  have  been  produced;  see
         signal(3C).
 
So, if you want to be really paranoid, you can check the lower 8
bits of the return value to find the return code of the process, and
you can also check the upper eight bits to make sure the process did
not exit because of a signal or a core dump.

If your program doesn't need to be quite that paranoid, you can just
take the return value from system % 256 to get the exit code for the
process you spawned.

perldoc perlfunc and page 230 of the blue Camel book cover this topic,
including code samples of how to handle the "more paranoid" cases.

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: 22 Sep 1997 22:06:11 GMT
From: "Michael A. Watson" <fishrman@shell.wco.com>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <606q4j$h92$1@news.wco.com>

You left out the total users that were told to read the FAQ or "get a good 
PERL book" instead of giving them useful help.



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

Date: 22 Sep 1997 20:08:28 GMT
From: c.c.eiftj@78.usenet.us.com (Rahul Dhesi)
Subject: symbolic dereferencing of my() variables -- can it be done?
Message-Id: <606j7s$9n3$1@samba.rahul.net>

I sometimes like to do something like this:

   use strict;
   @::variables = qw( a b c x y z );
   for (@::variables) {
      no strict 'refs';
      $$_ = &something($_);	# $a = &something('a') and so on
   }

But I also want to be able to do the same thing with my() variables, and
the symbolic dereferencing I am doing above does not work any more.  I
am forced to use eval instead:

   use strict;
   my @variables = qw( a b c x y z );
   for (@variables) {
      eval "\$$_ = &something('$_')";
   }

This is ugly.  Is there a better way of doing this?
-- 
Rahul Dhesi <dhesi@spams.r.us.com>


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

Date: 22 Sep 1997 19:16:27 GMT
From: "John Law" <John.R.Law@btinternet.com>
Subject: test
Message-Id: <01bcc78d$119c3fa0$213363c3@default>

Just testing


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

Date: Mon, 22 Sep 1997 20:16:50 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: test
Message-Id: <3426d216.16185984@igate.hst.moc.com>

[cc'd automagically to original author]

On 22 Sep 1997 19:16:27 GMT, "John Law" <John.R.Law@btinternet.com>
wrote:

>Just testing

There are newsgroups which exist solely for the purpose of test posts,
FYI...

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


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

Date: Mon, 22 Sep 1997 21:53:56 GMT
From: han@dataprompt.com (Weihan Chang)
Subject: Where is perl/Tk for Win32
Message-Id: <3426e89e.100201251@192.133.97.103>

Hi,
I saw someone mentioned about a version of perl/Tk on Win32(Windows
NT). Does anyone know where I can get a binary copy ?
Thanks a lot.



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

Date: Mon, 22 Sep 1997 21:06:29 GMT
From: neilb@cre.canon.co.uk (Neil Bowers)
Subject: where's the latest version of jcode.pl
Message-Id: <EGxHAt.n2y@cre.canon.co.uk>

I am using version 2.3 of jcode.pl. I remember seeing a mention
of patches to jcode.pl being maintained by someone else.

Can anyone point me to a more recent version, or other Perl code
for handling (conversion between) Japanese encodings.

cheers,
Neil
--
Abstraction is not easy.  Abstraction is hard.  Abstraction only makes
other things easy.  Sometimes.				-- Larry Wall


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

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

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