[31575] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2834 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 25 11:09:26 2010

Date: Thu, 25 Feb 2010 08:09:06 -0800 (PST)
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, 25 Feb 2010     Volume: 11 Number: 2834

Today's topics:
        Call for Paper The International Journal of Computer Sc <ijcsorgeditor@gmail.com>
        Can somebody explain fork clearly to me? <steve@staticg.com>
    Re: Can somebody explain fork clearly to me? <jurgenex@hotmail.com>
    Re: Can somebody explain fork clearly to me? <willem@snail.stack.nl>
    Re: Can somebody explain fork clearly to me? <thepoet_nospam@arcor.de>
    Re: Can somebody explain fork clearly to me? <tadmc@seesig.invalid>
    Re: Can somebody explain fork clearly to me? <derykus@gmail.com>
        Capturing System Command Output with Perl on Windows/Ap <helius@gmail.com>
    Re: Capturing System Command Output with Perl on Window <helius@gmail.com>
    Re: Capturing System Command Output with Perl on Window <helius@gmail.com>
    Re: Windows: How to sleep until key is pressed <dilbert1999@gmail.com>
    Re: Windows: How to sleep until key is pressed sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 24 Feb 2010 23:19:21 -0800 (PST)
From: editor ijcs <ijcsorgeditor@gmail.com>
Subject: Call for Paper The International Journal of Computer Science (IJCS)
Message-Id: <08c69fa2-2ab9-434a-8653-f4cec0695237@k6g2000prg.googlegroups.com>

Call for Paper
The International Journal of Computer Science (IJCS) publishes
original papers on all subjects relevant to computer science,
communication network, and information systems. The highest priority
will be given to those contributions concerned with a discussion of
the background of a practical problem, the establishment of an
appropriate model, the determination of a solution, approximate or
exact, analytical or numerical, and a discussion of the relevance of
the results when applied to the real-life problem. Paper submissions
are invited in the area of computer science, in particular the
technological advances and research results in the fields of
theoretical, experimental, applied electronics, computer science,
communication network and Information technology.
Topics of interest include but are not limited to the following:
     Computer Science

    * Parallel Processing and Distributed Computing
    * Foundations of High-performance Computing
    * Graph Theory and Analysis of Algorithms
    * Artificial Intelligences and Pattern/Image Recognitions
    * Neural Networks and Biomedical Simulations
    * Virtual Visions and Virtual Simulations
    * Data Mining, Web Image Mining and Applications
    * Data Base Management & Information Retrievals Adaptive Systems
    * Bifurcation, Biocybernetics & Bioinformatics
    * Blind Systems, Neural Networks &Control Systems
    * Cryptosystems &Data Compression
    * Evolutional Computation &Fuzzy Systems
    * Image Processing and Image Recognition, Modeling & Optimization
    * Speech Processing, Speech Synthesis & Speech Recognition
    * Video Signal Processing, Watermarking & Wavelet Transform
    * All topics related Computer Science

Communication Network

    * Quantum Computing & Coding
    * Error Controls Agent Computing & Multi-Agents Systems
    * Defining Spectrum Rights and Open Spectrum Solutions
    * Quality of Services and Communication Protocols
    * Satellite and Optical Communication Systems
    * 3G/4G Network Evolutions & CDMA/GSM Communication Protocols
    * Mobile Computing, Transmission/Switching/Distribution
technologies
    * Communication Theory & Signal Processing for Communications
    * Wireless Communications, Wireless & Mobile Networking
    * Optical Networks and Systems &Next-Generation Networking and
Internet
    * Communication QoS &Reliability and Modeling
    * Ad-hoc, Sensor & Mesh Networking
    * Multimedia Services, Communication Software & Services
    * Communication and Information System Security
    * System control and network/service management
    * Network and Internet protocols and standards
    * Client-server, distributed & Web-based communication systems
    * Broadband and multimedia systems & applications
    * Trials of advanced systems and services
    * Any topics related Communication Network

Information and Systems

    * Cryptography and Foundation of Computer Security
    * Authentication/Authorization Issues
    * IDS/Firewall, Anti-Spam mail & Anti-virus issues
    * Biometric authentication & algorithms
    * Fingerprint /Hand/Biometrics Recognitions and Technologies
    * IC-card Security, OTP & Key Management Issues
    * E-commerce, Ubiquitous & RFID Applications
    * Metadata, Meta Modeling, XML & Data Management
    * Knowledge Management, Web Security & Privacy
    * Cyber Threats, Web Services & Web Engineering
    * Web Intelligence, Protocols & Standards
    * Proxies and Servers
    * Multimedia Applications
    * Ontology and the Semantic Web
    * B2B, B2C and C2C
    * E-Business System Design and Development, E-Payment
    * Portal Strategies, Social Networks and Information Systems
    * Social and Legal Issues and Digital Ecology
    * E-Governance, E-Learning and Virtual Classrooms
    * E-Entertainment, E-Journalism
    * Any topics related Information systems

   Electronics

    * Circuits & Devices
    * Communication Networks & Systems
    * Communications & Information Processing
    * Digital Signal Processing & Electrical Engineering
Communications
    * Electromagnetics & Microwaves
    * Instrumentation
    * Measurement & Testing
    * Nanoscience & Nanotechnology
    * Optics & Optoelectronic Effects
    * Devices, Systems &Semiconductors
    * Systems & Control Engineering
    * Telecommunications
    * Any topics related Electronics

International Journal of Computer Science (IJCS)
ISSN: 1884-9083
Website: https://sites.google.com/site/ijcsorg/
Manuscript submission to: ijcsorgeditor@gmail.com

All submitted papers will be judged based on their quality by the
technical committee and reviewers. Papers that describe research and
experimentation are encouraged. All paper submissions will be handled
electronically and detailed instructions on submission procedure are
available on IJCS web pages. Researchers and authors are invited to
participate in the peer-review process of IJCS papers if your research
interest matches with the themes of Call for Papers. For other
information, please contact IJCS Managing Editor.


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

Date: Wed, 24 Feb 2010 11:20:28 -0800 (PST)
From: Steve <steve@staticg.com>
Subject: Can somebody explain fork clearly to me?
Message-Id: <32823cce-8853-4701-86ec-4f2fef4b0495@b9g2000pri.googlegroups.com>

As it clearly states on oreilly's site:
"The fork command actually creates a child process, and returns the
PID of the process to the parent, and a value of zero to the child"

My brain is having an implosion trying to understand code such as
this:
1. unless(fork)
2. if ($pid = fork)

that's like saying "unless 6124" where 6124 is a PID.  or if 6124, do
this, else to this.


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

Date: Wed, 24 Feb 2010 11:52:29 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Can somebody explain fork clearly to me?
Message-Id: <990bo59p3f7c9q7vf030mn1tuk0irmsi7u@4ax.com>

Steve <steve@staticg.com> wrote:
>As it clearly states on oreilly's site:
>"The fork command actually creates a child process, and returns the
>PID of the process to the parent, and a value of zero to the child"
>
>My brain is having an implosion trying to understand code such as
>this:
>1. unless(fork)
>2. if ($pid = fork)
>
>that's like saying "unless 6124" where 6124 is a PID.  or if 6124, do
>this, else to this.

Has nothing to do with fork() but with boolean values in Perl or
actually with scalars. In Perl any scalar can be used in many different
capacities and has simultaneously at least a string, a numerical, and a
boolean value. 
The boolean value of a number is false if and only if that number is 0.
Therefore ""unless 6124" is the same as "unless <true>". (*)

It is a convenient short-hand. If you prefer you can replace the "fork"
command with "fork != 0" and you will get exactly the same behaviour.

jue

*<true> indicating the true value, not the string '<true>', which on the
other hand is a true value itself.


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

Date: Wed, 24 Feb 2010 19:56:02 +0000 (UTC)
From: Willem <willem@snail.stack.nl>
Subject: Re: Can somebody explain fork clearly to me?
Message-Id: <slrnhob12i.287g.willem@snail.stack.nl>

Steve wrote:
) As it clearly states on oreilly's site:
) "The fork command actually creates a child process, and returns the
) PID of the process to the parent, and a value of zero to the child"
)
) My brain is having an implosion trying to understand code such as
) this:
) 1. unless(fork)
) 2. if ($pid = fork)
)
) that's like saying "unless 6124" where 6124 is a PID.  or if 6124, do
) this, else to this.

It's actually very simple.
As soon as fork() is executed, the following code is executed *twice*.
Once in the parent process and once in the child process.

At that point, the two processes are completely indistinguishable, except
for one thing: the return value of fork().

So, the if() that checks the value of the fork() call is actually making
sure that the parent process and the child process are then going in
different directions.

 if (my $pid = fork) {
   say "Hello, I am the parent process! The child process is $pid";
 } else {
   say "Hello, I am the child process!";
 }

In this piece of code (barring strange exceptions or typos on my part),
*both* 'say' statements will be executed.  One in the parent process,
one in the child process.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Wed, 24 Feb 2010 21:06:06 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Can somebody explain fork clearly to me?
Message-Id: <4b8586b0$0$6735$9b4e6d93@newsspool2.arcor-online.net>

Steve wrote:
> As it clearly states on oreilly's site:
> "The fork command actually creates a child process, and returns the
> PID of the process to the parent, and a value of zero to the child"
> 
> My brain is having an implosion trying to understand code such as
> this:
> 1. unless(fork)
> 2. if ($pid = fork)
> 
> that's like saying "unless 6124" where 6124 is a PID.  or if 6124, do
> this, else to this.

A value of numeric zero evaluates to false in boolean context, any
non-zero number evaluates to boolean true, so the above statements
could be expressed as:

1. unless(fork) {...}
    is equivalent to
      my $pid = fork();
      if( $pid == 0 ) { ... }

2. if( $pid = fork ) { ... }
      my $pid = fork();
      if( $pid > 0 ) { ... }

For clarification, just consider the following snippet:

for my $x ( 3,2,1,0,-1 ) {
   print $x . ": boolean ";
   if($x) {	# evaluate $x in boolean context
     print "true";
   } else {
     print "false";
   }
   print $/;
}

Keep in mind that Perl is all about context, and using a variable
together with a boolean operator or as an argument in a condition
forces the boolean context on it. For Perl this means that
undef, 0 and empty strings are "false" in boolean operations and
conditions - the same goes for empty lists or hashes, which are
flattened as scalars first returning their number of entries
(list/array) or used hash slots, which are both zero if the list/hash
contains no elements.

-Christian


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

Date: Wed, 24 Feb 2010 14:08:18 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Can somebody explain fork clearly to me?
Message-Id: <slrnhob1ii.hp7.tadmc@tadbox.sbcglobal.net>

Steve <steve@staticg.com> wrote:


> As it clearly states on oreilly's site:


No not use a website as your standard reference on Perl.

Use the standard docs that come with perl as your standard reference on
Perl.


> "The fork command actually creates a child process, and returns the
> PID of the process to the parent, and a value of zero to the child"


But if you insist on quoting from the web, then please provide
a URL that can be followed to see what you are quoting, along
with its context.


> My brain is having an implosion trying to understand code such as
> this:
> 1. unless(fork)
> 2. if ($pid = fork)


I think you need to review the "Truth and Falsehood" section in:

    perldoc perlsyn


> that's like saying "unless 6124" where 6124 is a PID.  or if 6124, do
> this, else to this.

Exactly so.

6124 is a "true" value.

"unless 6124" is "unless true" which does NOT execute the unless block.

"if 6124" is "if true" which DOES execute the if block.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"


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

Date: Wed, 24 Feb 2010 12:20:20 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Can somebody explain fork clearly to me?
Message-Id: <80695875-92fe-4d4b-8552-79bc6bd530fb@a16g2000pre.googlegroups.com>

On Feb 24, 11:20=A0am, Steve <st...@staticg.com> wrote:
> As it clearly states on oreilly's site:
> "The fork command actually creates a child process, and returns the
> PID of the process to the parent, and a value of zero to the child"
>
> My brain is having an implosion trying to understand code such as
> this:
> 1. unless(fork)
> 2. if ($pid =3D fork)
>
> that's like saying "unless 6124" where 6124 is a PID. =A0or if 6124, do
> this, else to this.

There will be 2 processes as soon as the fork below occurs
at runtime with fork() returning the child process id (PID,
eg 6124,  to the parent and 0 to the child itself.

   unless ( fork ) {  # or 'unless ($pid =3D fork)'
      .....
   } else  {  # child:  fork returns zero
       ....
   }

But, Perl's backend compiles the above to a separate fork
call followed by the branching logic. So, after the fork,
both parent and child exist and each can evaluate fork's
return and branch correctly.

--
Charles DeRykus


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

Date: Thu, 25 Feb 2010 07:15:39 -0800 (PST)
From: Jasper2000 <helius@gmail.com>
Subject: Capturing System Command Output with Perl on Windows/Apache
Message-Id: <9f86f5f7-c660-4f96-bdb7-d35cb77f35c3@19g2000yqu.googlegroups.com>

Hi,

I have a problem trying to figure out why my Perl script, which works
fine from a DOS prompt, won't work when running via http.

The script simply does a quick "whois" and is meant to output the
results. When run from DOS it works fine, but when running under http
it ends up never finishing, never outputting anything, and with an
error in the error log (if I don't use eval), per the below:

(70007)The timeout specified has expired: ap_content_length_filter:
apr_bucket_read() failed

So, I've tried this a couple of different ways, but the most recent
incarnation, with pretty printing stripped out, is below:

# -------

my $cmd	=join('','c:/apache/cgi/whois.exe',' ',$host);

undef my @results;

eval {
    local $SIG{ALRM} = sub { die "TIMEDOUT" };
    alarm(10);
    @results	=`$cmd`;     # i.e. using back-ticks
    alarm(0);
};

print @results;

# -------

I am really curious, not to mention a little frustrated, since I know
that from the command line it works fine, and is very fast (usually a
response within a second or so).

Perl = version 5.8.
Apache = 2.x.
O.S. = XP Pro.

Any assistance appreciated.

Thanks!







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

Date: Thu, 25 Feb 2010 07:18:04 -0800 (PST)
From: Jasper2000 <helius@gmail.com>
Subject: Re: Capturing System Command Output with Perl on Windows/Apache
Message-Id: <cb563710-ce15-47a9-a0f4-bd0792a3b798@u9g2000yqb.googlegroups.com>

Yes, I am printing http headers, etc. :-)




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

Date: Thu, 25 Feb 2010 07:51:06 -0800 (PST)
From: Jasper2000 <helius@gmail.com>
Subject: Re: Capturing System Command Output with Perl on Windows/Apache
Message-Id: <3065b0ea-4a3c-47fc-86a0-5022e94a12ea@k17g2000yqb.googlegroups.com>

Whoa ... The weirdest thing .. I have now got it working, and will
explain below, but I still don't know exactly why it makes a
difference ... If someone can explain that would be even better!

In short, it was not a Perl issue.

What I did was to right-click on my whois.exe program and go into
Properties, and then select the Compatibility tab. In the
Compatibility tab one has the option to run a Windows program in
various compatibility modes (i.e. run it in Windows 95 compatibility
mode, or Windows 98, etc, etc). Anyway, I selected Windows 95
Compatibility mode, and lo-and-behold I am now getting output in http,
which I was not before.

I suspect if other people have third-party programs, for which they
are having a similar problem, then this might be something worth
trying.



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

Date: Wed, 24 Feb 2010 12:37:47 -0800 (PST)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: Windows: How to sleep until key is pressed
Message-Id: <49c749ad-c1da-44bb-9e24-511a896523b3@k41g2000yqm.googlegroups.com>

On 23 f=E9v, 23:24, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "Peter J. Holzer" <hjp-usen...@hjp.at>:
> > There is in fact one Unix system call (and corresponding Perl builtin
> > function) which has exactly the semantics Dilbert wants:
>
> > =A0 =A0 select
>
> Unfortunately select doesn't generally work on Win32, since it doesn't
> have a proper unified fd model. The perl builtin calls a version that
> only works on sockets.
>
> The native Win32 replacement for select(2) is WaitForMultipleObjects,
> which will wait for any HANDLE. This is wrapped by the Win32::IPC
> module.
>
> Arguably perl's select on Win32 ought to use WFMO to provide semantics
> more like Unix' select(2), but it doesn't.

Hurray !
I have resolved my problem - Thanks to everybody who responded

I am now using wait_any() of Win32::IPC, and it works perfectly.

Here is the complete program:

use strict;
use warnings;

use Win32::Console;
use Win32::IPC qw(wait_any);

my $CONS_INP =3D Win32::Console->new(STD_INPUT_HANDLE);
my @CONS_INL =3D ($CONS_INP);

LOOP1: while (1) {
    # I want to sleep here until a key is pressed...
    # How can I achieve this under Windows... ???
    # use Win32::IPC does the trick.
    # WaitForMultipleObjects([$CONS_INP]); # this works, but is
deprecated.

    wait_any(@CONS_INL); # this works and is not deprecated

    while ($CONS_INP->GetEvents) {
        my @event =3D $CONS_INP->Input;

        local $" =3D "', '";
        print "event =3D ('@event')\n";

        last LOOP1 if $event[5] and $event[5] =3D=3D 27; # Escape key
    }
}


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

Date: Wed, 24 Feb 2010 16:18:12 -0800
From: sln@netherlands.com
Subject: Re: Windows: How to sleep until key is pressed
Message-Id: <acfbo5538ecl9dvlc35uu1na4d35vhiehr@4ax.com>

On Wed, 24 Feb 2010 12:37:47 -0800 (PST), Dilbert <dilbert1999@gmail.com> wrote:

[snip]

>Hurray !
>I have resolved my problem - Thanks to everybody who responded
>
>I am now using wait_any() of Win32::IPC, and it works perfectly.
>
>Here is the complete program:
>
>use strict;
>use warnings;
>
>use Win32::Console;
>use Win32::IPC qw(wait_any);
>
>my $CONS_INP = Win32::Console->new(STD_INPUT_HANDLE);
>my @CONS_INL = ($CONS_INP);
>
>LOOP1: while (1) {
>    # I want to sleep here until a key is pressed...
>    # How can I achieve this under Windows... ???
>    # use Win32::IPC does the trick.
>    # WaitForMultipleObjects([$CONS_INP]); # this works, but is
>deprecated.
>
>    wait_any(@CONS_INL); # this works and is not deprecated
>
>    while ($CONS_INP->GetEvents) {
>        my @event = $CONS_INP->Input;
>
>        local $" = "', '";
>        print "event = ('@event')\n";
>
>        last LOOP1 if $event[5] and $event[5] == 27; # Escape key
>    }
>}

Thats great. I'm suprised they had 'WaitForMultipleObjects'
as a method. Its not depricated in vc 2005, thats for sure.

You can also get/set the input console mode like this:
----------------------
my %val2mode = (
  '0004' => 'ENABLE_ECHO_INPUT',
  '0032' => 'ENABLE_INSERT_MODE',
  '0002' => 'ENABLE_LINE_INPUT',
  '0016' => 'ENABLE_MOUSE_INPUT',
  '0001' => 'ENABLE_PROCESSED_INPUT',
  '0064' => 'ENABLE_QUICK_EDIT_MODE',
  '0008' => 'ENABLE_WINDOW_INPUT',
  '0128' => 'UNKNOWN',
  '0256' => 'UNKNOWN'
);
my %mode2val = reverse %val2mode;
my $curmode = $CONS_INP->Mode();

print "Current modes ($curmode):\n";
for my $val (map {1<<$_} 0 .. 10) {
    if ($val & $curmode) {
        if (exists $val2mode{ $val=sprintf ("%04s", $val) } ) {
            print "  $val - $val2mode{ $val }\n";
        }
    }
}
#$CONS_INP->Mode( $curmode | $mode2bit{ENABLE_MOUSE_INPUT}); ...
------------------

Good job!

-sln

Just a side note .., your getting key-down events.
Key-down events are almost never used except in games.
They generate a constant event stream when keys are held down.
I don't know about Win32::Console, but in the bowels of win32
you can filter out key-down events (not control state) before
it ever gets to the event queue (ie: the win32 input event buffer).

Key-up events is what is of normal interest. Its a little
more meaningfull if they can filtered.
Note the control key (states) with each key-up event as well.

Example:
---------------
    while ($CONS_INP->GetEvents) {
        my @event = $CONS_INP->Input;
        if (@event)  # no event mean error
        {
            # KEYS ... 
            if ($event[0] == 1) {
                next unless $event[1]==0; # Only process key-up events

                local $" = "', '";
                print "event = ('@event')\n";
                last LOOP1 if $event[5] == 27; # Escape key
            }
            # MOUSE ... (if ENABLE_MOUSE_INPUT)
            if ($event[0] == 2) {
                #
            }
        }
    }



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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 2834
***************************************


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