[30507] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1750 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 28 09:09:47 2008

Date: Mon, 28 Jul 2008 06:09:08 -0700 (PDT)
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, 28 Jul 2008     Volume: 11 Number: 1750

Today's topics:
        Callback/hooks/events handler code needed doar.meyutar@gmail.com
    Re: Callback/hooks/events handler code needed (Zak B. Elep)
    Re: FAQ 4.2 Why is int() broken? <szrRE@szromanMO.comVE>
    Re: FAQ 4.2 Why is int() broken? <jurgenex@hotmail.com>
    Re: FAQ 4.2 Why is int() broken? <tadmc@seesig.invalid>
    Re: FAQ 4.2 Why is int() broken? <hjp-usenet2@hjp.at>
        new CPAN modules on Mon Jul 28 2008 (Randal Schwartz)
        Parallel search in Perl and other languages <hjp-usenet2@hjp.at>
        perl-learn it veryeasily <amutha4f@gmail.com>
        Running in the background (via &) <Mark.Seger@hp.com>
    Re: Running in the background (via &) <josef.moellers@fujitsu-siemens.com>
    Re: Running in the background (via &) <Mark.Seger@hp.com>
    Re: strange behavior of ?? <user@serverrb.net>
    Re: strange behavior of ?? (Zak B. Elep)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 27 Jul 2008 23:49:45 -0700 (PDT)
From: doar.meyutar@gmail.com
Subject: Callback/hooks/events handler code needed
Message-Id: <61e0f8a1-ffd6-475e-8aeb-47d2e55237ef@d1g2000hsg.googlegroups.com>

Hi all,

I need to add a Perl module to my code that handles events/hooks/
callbacks
(I don't really have a name preference here :-) )

What I need is to have the option for other modules to register
events, or
subroutines to be called when events happen. I am betting there's a
generic
implementation already working and would be happy to use it instead
of
coding it again myself.

Any suggestions?

Thanks,
Oren



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

Date: Mon, 28 Jul 2008 16:40:37 +0800
From: zakame@zakame.net (Zak B. Elep)
Subject: Re: Callback/hooks/events handler code needed
Message-Id: <m2r69e4d16.fsf@zakame.net>

doar.meyutar@gmail.com writes:

> I need to add a Perl module to my code that handles events/hooks/
> callbacks (I don't really have a name preference here :-) )
>
> What I need is to have the option for other modules to register events,
> or subroutines to be called when events happen. I am betting there's a
> generic implementation already working and would be happy to use it
> instead of coding it again myself.

Module::Pluggable[1] came to mind.  I'm sure there are others; do check
the CPAN.[2]


Footnotes: 
[1]  http://search.cpan.org/perldoc?Module::Pluggable

[2]  http://search.cpan.org/search?query=pluggable&mode=all

-- 
  I like the idea of 256 bits, though: 32 for the (Unicode) character leaves
  room for 224 Bucky bits, which ought to be enough for anyone.
				-- Roland Hutchinson, in alt.folklore.computers


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

Date: Sun, 27 Jul 2008 22:02:21 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <g6jjt80316n@news4.newsguy.com>

Peter J. Holzer wrote:
> On 2008-07-25 19:00, szr <szrRE@szromanMO.comVE> wrote:
>> Peter J. Holzer wrote:
>>> On 2008-07-24 16:19, szr <szrRE@szromanMO.comVE> wrote:
>>>> Seems you need the extra precision that building Perl with "long
>>>> double" support
>>>
>>> No. The extra precision doesn't help. As I argued below it's just
>>> coincidence that error isn't noticable in this case. if you use
>>> other numbers instead of 0.6 and 0.2, you will discover some where
>>> the result is "wrong" even with 96 bits. Indeed you may find some
>>> where the result is correct for 64 bits and wrong for 96 bits.
>>
>> Is there any way to get a lore more precision than 96 or 128 bits,
>
> Please get it into your head that extra precision *does* *not* solve
> this problem. To express 1/10 in binary you need an infinite number of
> digits, just like you need an infinite number of digits to express 1/3
> in decimal.

Maybe you meant to write something else, as 1/10 is 0.1 and does not 
require an infinite number of digits; it needs just one decimal digit 
:-)

Secondly, for expressions like 1/3, yes, the floating point (decimal) 
form cannot be fully expressed in binary. However, in the form of a 
rational number, it can be stored in an accurate binary form, as you're 
really storing integers - the numerator and the denominator - although 
I'm not sure if that would be faster or slower than actual floating 
point calculations; I've never done the numbers, and I'm sure it may 
vary depending on the processor, but I have seen libraries, such as in C 
or C++, that use rational instead of floating point numbers.

If what you're after is accurate math, than representing your numbers as 
rational (n/d) seems to be a rather trivial way of achieving that; the 
math part most people learned in basic arithmetic. I would think the 
hardest part would be writing an efficient reduction algorithm, to, for 
example, turn 10/18 into 5/9.

> If you need to express decimals exactly, use decimal numbers. If you
> need to express rational numbers exactly, use rational numbers.

Hey, there you go; what I just wrote summed up nicely :-)

>> or is it better to write (or find) a module that does "moving"
>> calculations, kind of like a certain Linux console program whose name
>> I cannot recall.
>
> You mean "bc".

Yep, that's the one.

> I'm not sure what you mean by "moving" calculations. Bc
> does decimal fixed point arithmetic with arbitrary precision. There
> are a number of perl modules which do aribtrary precision:
> Math::BigInt, Math::BigFloat and Math::BigRat.

Yeah that's what I meant by "moving", as in it just keeps on calculating 
on and on and on given how many places.

-- 
szr 




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

Date: Mon, 28 Jul 2008 06:12:01 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <2jnq845bdlnlom24j7lvr8t2heg9n93adh@4ax.com>

"szr" <szrRE@szromanMO.comVE> wrote:
>Peter J. Holzer wrote:
>> Please get it into your head that extra precision *does* *not* solve
>> this problem. To express 1/10 in binary you need an infinite number of
>> digits, just like you need an infinite number of digits to express 1/3
>> in decimal.
>
>Maybe you meant to write something else, as 1/10 is 0.1 and does not 
>require an infinite number of digits; 

Yes, it does.

>it needs just one decimal digit 

Irrelevant because your typical computer does not use decimal numbers
but binary numbers, just like Peter said.

>Secondly, for expressions like 1/3, yes, the floating point (decimal) 
>form cannot be fully expressed in binary. However, in the form of a 
>rational number, it can be stored in an accurate binary form, 

No, it cannot. Neither as a decimal number nor as a binary number.

>as you're 
>really storing integers - the numerator and the denominator - 

That is not a number but an expresssion. Mathematically they may be the
same. However for actual computations they are not as any introduction
to Computer Numerics will tell you.

>although 
>I'm not sure if that would be faster or slower than actual floating 
>point calculations; I've never done the numbers, and I'm sure it may 
>vary depending on the processor, but I have seen libraries, such as in C 
>or C++, that use rational instead of floating point numbers.

Yep, there are special mathematical packages out there for symbolic
arithmetic. They can handle fractions and typically much more from
simple sums all the way up to integrals and difference quotients.

>If what you're after is accurate math, than representing your numbers as 
>rational (n/d) seems to be a rather trivial way of achieving that; the 
>math part most people learned in basic arithmetic. I would think the 
>hardest part would be writing an efficient reduction algorithm, to, for 
>example, turn 10/18 into 5/9.

Smallest common demoninator, rather simple. But any operations on such
symbolic numbers is time consuming because it is not supported by
hardware but needs to be emulated in software.

>> If you need to express decimals exactly, use decimal numbers. If you

Again, your typical computer does not use decimal numbers but binary
numbers. There have been a few CPUs with build-in support for decimal
calculations, but they weren't very successful.

>> need to express rational numbers exactly, use rational numbers.

I suppose you meant "use fractions". 
Again, except for maybe very specialized high-end computers fractions
are not supported by the hardware.

jue


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

Date: Mon, 28 Jul 2008 05:51:41 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <slrng8r95t.5lr.tadmc@tadmc30.sbcglobal.net>

szr <szrRE@szromanMO.comVE> wrote:
> Peter J. Holzer wrote:

>> To express 1/10 in binary you need an infinite number of
                   ^^^^^^^^^
                   ^^^^^^^^^
>> digits,


> Maybe you meant to write something else, as 1/10 is 0.1 and does not 
> require an infinite number of digits; it needs just one decimal digit 


He did not say that it required an infinite number of decimal digits.

He said that it required an infinite number of binary digits.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Mon, 28 Jul 2008 14:49:46 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <slrng8rg3a.pia.hjp-usenet2@hrunkner.hjp.at>

On 2008-07-28 06:12, Jürgen Exner <jurgenex@hotmail.com> wrote:
> "szr" <szrRE@szromanMO.comVE> wrote:
>>Peter J. Holzer wrote:
>>> Please get it into your head that extra precision *does* *not* solve
>>> this problem. To express 1/10 in binary you need an infinite number of
>>> digits, just like you need an infinite number of digits to express 1/3
>>> in decimal.
>>
>>Maybe you meant to write something else, as 1/10 is 0.1 and does not 
>>require an infinite number of digits; 
>
> Yes, it does.

It doesn't, but I didn't write that. I wrote it takes an infinite number
of *binary* digits.

In binary, 1/10 is 0.00011001100110011...


>>it needs just one decimal digit 
>
> Irrelevant because your typical computer does not use decimal numbers
> but binary numbers, just like Peter said.

Actually, I didn't write what "a typical computer" uses, just what
happens when a binary system is used (which is what perl uses on most
(all?) platforms - COBOL uses normally uses decimal).

>>Secondly, for expressions like 1/3, yes, the floating point (decimal) 
>>form cannot be fully expressed in binary. However, in the form of a 
>>rational number, it can be stored in an accurate binary form, 
>
> No, it cannot. Neither as a decimal number nor as a binary number.

Actually it can, at least if you translate the mathematical definition
of a rational number into the straightforward implementation of storing
two integers: (1, 3) in this case.


>>as you're 
>>really storing integers - the numerator and the denominator - 
>
> That is not a number but an expresssion. Mathematically they may be the
> same. However for actual computations they are not as any introduction
> to Computer Numerics will tell you.

It isn't much different from a floating point number, which is also
stored as two integers (m, e) where the value is m*2^(e-b). 


>>although I'm not sure if that would be faster or slower than actual
>>floating point calculations; I've never done the numbers, and I'm sure
>>it may vary depending on the processor, but I have seen libraries,
>>such as in C or C++, that use rational instead of floating point
>>numbers.

There is also one in Perl and I already mentioned it: Math::BigRat resp.
bigrat. That almost certainly is slow, because it not only uses rational
numbers, it also uses arbitrary precision. (But I've never really used
it so I don't know).


>>If what you're after is accurate math, than representing your numbers as 
>>rational (n/d) seems to be a rather trivial way of achieving that; the 
>>math part most people learned in basic arithmetic. I would think the 
>>hardest part would be writing an efficient reduction algorithm, to, for 
>>example, turn 10/18 into 5/9.
>
> Smallest common demoninator, rather simple.

Yup, was probably my third or fourth BASIC program. Used as an example
to introduce GOTO ;-).

	hp


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

Date: Mon, 28 Jul 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Jul 28 2008
Message-Id: <K4p92L.1t8B@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

AI-DecisionTree-0.09
http://search.cpan.org/~kwilliams/AI-DecisionTree-0.09/
Automatically Learns Decision Trees 
----
Acme-Uenicoede-0.05
http://search.cpan.org/~schwigon/Acme-Uenicoede-0.05/
----
Apache-SWIT-0.36
http://search.cpan.org/~bosu/Apache-SWIT-0.36/
mod_perl based application server with integrated testing. 
----
App-ZofCMS-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-0.0101/
web framework and templating system for small-medium sites. 
----
App-ZofCMS-0.0102
http://search.cpan.org/~zoffix/App-ZofCMS-0.0102/
web framework and templating system for small-medium sites. 
----
App-ZofCMS-0.0103
http://search.cpan.org/~zoffix/App-ZofCMS-0.0103/
web framework and templating system for small-medium sites. 
----
App-ZofCMS-Plugin-QueryToTemplate-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-QueryToTemplate-0.0101/
ZofCMS plugin to automagically make query parameters available in the template 
----
App-ZofCMS-Plugin-TOC-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-TOC-0.0101/
Table of Contents building plugin for ZofCMS 
----
App-ZofCMS-Plugin-TOC-0.0102
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-TOC-0.0102/
Table of Contents building plugin for ZofCMS 
----
App-ZofCMS-Plugin-Tagged-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-Tagged-0.0101/
ZofCMS plugin to fill templates with data from query, template variables and configuration using <TAGS> 
----
App-ZofCMS-Test-Plugin-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Test-Plugin-0.0101/
test module for testing ZofCMS plugins 
----
Bundle-DBD-PO-0.04
http://search.cpan.org/~steffenw/Bundle-DBD-PO-0.04/
A bundle to install all DBD::PO related modules 
----
CGI-AutoForm-1.03
http://search.cpan.org/~rsandberg/CGI-AutoForm-1.03/
Automated abstraction of HTML forms from a data source 
----
Catalyst-Controller-POD-0.01_02
http://search.cpan.org/~perler/Catalyst-Controller-POD-0.01_02/
The great new Catalyst::Controller::POD! 
----
Compress-LZMA-Simple-0.1
http://search.cpan.org/~mikio/Compress-LZMA-Simple-0.1/
----
DBD-PO-0.04
http://search.cpan.org/~steffenw/DBD-PO-0.04/
DBI driver for PO files 
----
DBIx-Class-Graph-0.01_02
http://search.cpan.org/~perler/DBIx-Class-Graph-0.01_02/
Represent a graph in a relational database using DBIC 
----
DBIx-Class-Storage-CacheProxy-0.01
http://search.cpan.org/~gugu/DBIx-Class-Storage-CacheProxy-0.01/
Caching layer for DBIx::Class 
----
DBIx-Knowledge-1.12
http://search.cpan.org/~rsandberg/DBIx-Knowledge-1.12/
Report creation on linear convergent data sets for Business Intelligence 
----
Data-Rlist-1.44
http://search.cpan.org/~aspindler/Data-Rlist-1.44/
----
DateTime-Format-Span-0.0.1
http://search.cpan.org/~dmuey/DateTime-Format-Span-0.0.1/
Get a locale specific string describing the span of a given duration 
----
Exception-Class-Nested-0.01
http://search.cpan.org/~jenda/Exception-Class-Nested-0.01/
Nested declaration of Exception::Class classes 
----
Foorum-0.2.0
http://search.cpan.org/~fayland/Foorum-0.2.0/
Foorum is a forum script built in Catalyst. 
----
GPS-Point-0.07
http://search.cpan.org/~mrdvt/GPS-Point-0.07/
Provides an object interface for a GPS point. 
----
GPS-Point-0.08
http://search.cpan.org/~mrdvt/GPS-Point-0.08/
Provides an object interface for a GPS point. 
----
Geo-Sun-0.04
http://search.cpan.org/~mrdvt/Geo-Sun-0.04/
Calculates the Geodetic Position of the Sun over the Surface of the Earth 
----
Graphics-Primitive-0.07
http://search.cpan.org/~gphat/Graphics-Primitive-0.07/
Device and library agnostic graphics objects 
----
HTML-Perlinfo-1.54
http://search.cpan.org/~accardo/HTML-Perlinfo-1.54/
Display a lot of Perl information in HTML format 
----
Ham-Reference-Phonetics-0.01
http://search.cpan.org/~bradmc/Ham-Reference-Phonetics-0.01/
A quick reference for the ITU Phonetic Alphabet. 
----
Ham-Reference-Qsignals-0.01
http://search.cpan.org/~bradmc/Ham-Reference-Qsignals-0.01/
A quick reference for Q Signals. 
----
Ham-Reference-Solar-0.01
http://search.cpan.org/~bradmc/Ham-Reference-Solar-0.01/
Get basic solar data from the web that's useful for Amateur Radio applications. 
----
IO-Handle-unread-0.02
http://search.cpan.org/~gfuji/IO-Handle-unread-0.02/
Pushes string back into input filehandle 
----
Locale-Maketext-Utils-0.0.12
http://search.cpan.org/~dmuey/Locale-Maketext-Utils-0.0.12/
Adds some utility functionality and failure handling to Local::Maketext handles 
----
Log-Handler-0.46
http://search.cpan.org/~bloonix/Log-Handler-0.46/
Log messages to several outputs. 
----
MIDI-Tweaks-0.06
http://search.cpan.org/~jv/MIDI-Tweaks-0.06/
Enhancements to MIDI.pm. 
----
Math-GSL-0.06_01
http://search.cpan.org/~leto/Math-GSL-0.06_01/
Perl interface to the GNU Scientific Library (GSL) using SWIG 
----
Math-GSL-0.06_02
http://search.cpan.org/~leto/Math-GSL-0.06_02/
Perl interface to the GNU Scientific Library (GSL) using SWIG 
----
Naming-Convention-0.0.2
http://search.cpan.org/~sunnavy/Naming-Convention-0.0.2/
Naming or Renaming( for identifiers, mostly ) 
----
Naming-Convention-0.0.3
http://search.cpan.org/~sunnavy/Naming-Convention-0.0.3/
Naming or Renaming( for identifiers, mostly ) 
----
Naming-Convention-0.0.4
http://search.cpan.org/~sunnavy/Naming-Convention-0.0.4/
Naming or Renaming( for identifiers, mostly ) 
----
Naming-Convention-0.0.5
http://search.cpan.org/~sunnavy/Naming-Convention-0.0.5/
Naming or Renaming( for identifiers, mostly ) 
----
Parallel-MapReduce-0.07
http://search.cpan.org/~drrho/Parallel-MapReduce-0.07/
MapReduce Infrastructure, multithreaded 
----
Parallel-MapReduce-0.08
http://search.cpan.org/~drrho/Parallel-MapReduce-0.08/
MapReduce Infrastructure, multithreaded 
----
Parse-Flex-0.12
http://search.cpan.org/~ioannis/Parse-Flex-0.12/
The Fastest Lexer in the West 
----
PerlIO-Util-0.55
http://search.cpan.org/~gfuji/PerlIO-Util-0.55/
A selection of general PerlIO utilities 
----
PerlIO-Util-0.56
http://search.cpan.org/~gfuji/PerlIO-Util-0.56/
A selection of general PerlIO utilities 
----
PodToHTML-0.08
http://search.cpan.org/~bdfoy/PodToHTML-0.08/
----
Pugs-Compiler-Rule-0.35
http://search.cpan.org/~fglock/Pugs-Compiler-Rule-0.35/
Compiler for Perl 6 regexes 
----
Runops-Trace-0.12
http://search.cpan.org/~nuffin/Runops-Trace-0.12/
Trace your program's execution 
----
String-Rexx-0.07
http://search.cpan.org/~ioannis/String-Rexx-0.07/
Perl implementation of Rexx string functions 
----
Syntax-Highlight-Engine-Simple-0.06
http://search.cpan.org/~jamadam/Syntax-Highlight-Engine-Simple-0.06/
Simple Syntax Highlight Engine 
----
Syntax-Highlight-Engine-Simple-0.07
http://search.cpan.org/~jamadam/Syntax-Highlight-Engine-Simple-0.07/
Simple Syntax Highlight Engine 
----
Sys-Protect-0.02
http://search.cpan.org/~bradfitz/Sys-Protect-0.02/
deny a bunch of opcodes 
----
Test-Harness-3.13
http://search.cpan.org/~andya/Test-Harness-3.13/
Run Perl standard test scripts with statistics 
----
Test-Out-0.21
http://search.cpan.org/~ldavis/Test-Out-0.21/
Test output from FILEHANDLE 
----
Test-Perl-Critic-Progressive-0.03
http://search.cpan.org/~thaljef/Test-Perl-Critic-Progressive-0.03/
Gradually enforce coding standards. 
----
Text-Naming-Convention-0.0.5
http://search.cpan.org/~sunnavy/Text-Naming-Convention-0.0.5/
Naming or Renaming( for identifiers, mostly ) 
----
Tk-EntrySet-0.03
http://search.cpan.org/~lamprecht/Tk-EntrySet-0.03/
display/edit a list of values in a Set of Widgets. 
----
WWW-Ohloh-API-0.2.0
http://search.cpan.org/~yanick/WWW-Ohloh-API-0.2.0/
Ohloh API implementation 
----
WWW-Search-Search-1.015
http://search.cpan.org/~mthurn/WWW-Search-Search-1.015/
class for searching www.search.com 
----
XML-LibXML-SAX-ChunkParser-0.00001
http://search.cpan.org/~dmaki/XML-LibXML-SAX-ChunkParser-0.00001/
Parse XML Chunks Via LibXML SAX 
----
criticism-1.02
http://search.cpan.org/~thaljef/criticism-1.02/
Perl pragma to enforce coding standards and best-practices 
----
pod-mode-0.501
http://search.cpan.org/~schwigon/pod-mode-0.501/
----
v6-0.028
http://search.cpan.org/~fglock/v6-0.028/
An experimental Perl 6 implementation 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Mon, 28 Jul 2008 15:00:24 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Parallel search in Perl and other languages
Message-Id: <slrng8rgn8.pia.hjp-usenet2@hrunkner.hjp.at>

I seem to be completely unable to find the right keywords to feed into
google, but I vaguely remember that it was mentioned in this group, so
I'm asking here in the hope that somebody has better memory than me:

Some guy has programmed a relatively simple task (I'm almost but not
quite sure it was a search in a file) using multiple processes/threads
in several languages to show that even for such tasks multiprocessing
gives you better performance. Other people contributed equivalent
programs in other languages, so he now has a nice collection of one or
two dozen implementations of the same task in different languages. Last
time I looked, the Perl implementation was the fastest.

Does anyone remember this, and if so, did you bychance bookmark the
site?

	hp



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

Date: Mon, 28 Jul 2008 04:32:35 -0700 (PDT)
From: goodluck <amutha4f@gmail.com>
Subject: perl-learn it veryeasily
Message-Id: <3ffef230-09da-4ea7-8008-ea5789a266ea@w39g2000prb.googlegroups.com>

http://www.artsandcraftsu.blogspot.com/


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

Date: Mon, 28 Jul 2008 07:26:41 -0400
From: Mark Seger <Mark.Seger@hp.com>
Subject: Running in the background (via &)
Message-Id: <g6kadn$gvg$1@usenet01.boi.hp.com>

I have the following simple script.

#!/usr/bin/perl -w
print `resize`;

If I run it in the foreground it works just fine, but if I run it in the 
background it hangs until I foreground it.  Is there  a way to tell if 
you're running in the background - it may be a UNIX feature that you 
cannot.  Otherwise, is there some way to diddle the environment (perhaps 
redirecting file descriptors) so it won't hang?

-mark


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

Date: Mon, 28 Jul 2008 13:50:00 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Running in the background (via &)
Message-Id: <g6kbo8$j6o$1@nntp.fujitsu-siemens.com>

Mark Seger wrote:
> I have the following simple script.
> 
> #!/usr/bin/perl -w
> print `resize`;
> 
> If I run it in the foreground it works just fine, but if I run it in the 
> background it hangs until I foreground it.  Is there  a way to tell if 
> you're running in the background - it may be a UNIX feature that you 
> cannot.

In a sense: you cannot as in *ix there is actually no conceptual 
difference between a "foreground" and a "background" process.

The terms "foreground" and "background" are used to distinguish between 
processes that the shell waits for and those that the shell doesn't wait 
for (e.g. thos started with an ampersand). So it's the parent who 
defines whether a process is a background process or a foreground 
process and then, even that may change, e.g. if you start a process, do 
quite a lot of different stuff (the new process could then be viewed as 
running in the background), then wait for the process (it might then be 
seen as a foreground process) until you are taken out of the wait() by a 
signal, and continue (which would turn your process into a background 
process again).
Also with some shells you can actively change processes between fore- 
and background.

>  Otherwise, is there some way to diddle the environment (perhaps 
> redirecting file descriptors) so it won't hang?

Would it help to have an indication whether you're in the foreground or 
in the background?
Usually background processes aren't connected to a terminal, most 
important, STDIN won't be connected to a terminal as then two processes 
(the current "foreground" process and the "background" process) contend 
for the input from the keyboard, so you could check whether STDIN is a 
terminal.
This will fail if you have a foreground process that has stdin 
redirected from a file or from a pipe, though.

HTH,

Josef
-- 
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html


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

Date: Mon, 28 Jul 2008 07:55:42 -0400
From: Mark Seger <Mark.Seger@hp.com>
To: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Running in the background (via &)
Message-Id: <488DB3BE.8070704@hp.com>

\
> Would it help to have an indication whether you're in the foreground or 
> in the background?
> Usually background processes aren't connected to a terminal, most 
> important, STDIN won't be connected to a terminal as then two processes 
> (the current "foreground" process and the "background" process) contend 
> for the input from the keyboard, so you could check whether STDIN is a 
> terminal.
that's what I thought and so did a -t STDIN, but it shows true whether 
in the foreground or background.
-mark


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

Date: Sun, 27 Jul 2008 23:43:46 -0500
From: Nathan <user@serverrb.net>
Subject: Re: strange behavior of ??
Message-Id: <n7cjk.13629$LG4.6706@nlpi065.nbdc.sbc.com>

Zak B. Elep wrote:
> Nathan <user@serverrb.net> writes:
> 
>> #!/usr/bin/perl
>> $_ = "Bilbo Baggins";
>> for (0..4) {
>>     $a = ?Bilbo?;
>> }
>>
>> Initially $a is not defined and then it stays '' on each loop pass. I am
>> running perl v5.8.8 on linux. My understanding is these two programs are
>> supposed to be equivalent, so why am I observing different behavior with
>> the debugger in the second one?
> 
> It is because you're aliasing the $_ to the elements of 0..4 in the
> for() loop, which not what you expect when you assigned a string to it.
> You should then use another scalar in the for() to alias the elements
> to, for instance:
> 
> ,----
> | $_ = "Bilbo Baggins";
> | for my $count ( 0 .. 4 ) {
> |     $a = ?Bilbo?;
> |     print "At $count, \$a is $a\n";
> | }
> `----
> 
  Thanks very much, that was very confusing to me. Perl does so many 
things automatically and behind the scenes I can't imagine coding in it 
*without* the debugger...

-Nathan


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

Date: Mon, 28 Jul 2008 13:08:37 +0800
From: zakame@zakame.net (Zak B. Elep)
Subject: Re: strange behavior of ??
Message-Id: <m2vdyq4mui.fsf@zakame.net>

Nathan <user@serverrb.net> writes:

>  Thanks very much, that was very confusing to me. Perl does so many
> things automatically and behind the scenes I can't imagine coding in it
> *without* the debugger...

`perl -de 0' provides a nice basic interactive perl.  Devel::REPL[1] is
also a fine alternative for quickly testing out/debugging code. :)


Footnotes: 
[1]  http://search.cpan.org/perldoc?Devel::REPL

-- 
  I like the idea of 256 bits, though: 32 for the (Unicode) character leaves
  room for 224 Bucky bits, which ought to be enough for anyone.
				-- Roland Hutchinson, in alt.folklore.computers


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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.

#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 V11 Issue 1750
***************************************


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