[29818] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1061 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 25 03:09:38 2007

Date: Sun, 25 Nov 2007 00:09:04 -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           Sun, 25 Nov 2007     Volume: 11 Number: 1061

Today's topics:
        =?ISO-8859-1?Q?named_pipe_and_"Text_file_busy"?= mikexf@gmail.com
    Re: =?ISO-8859-1?Q?named_pipe_and_"Text_file_busy"?= <ben@morrow.me.uk>
    Re: Can you detect that a process is waiting on stdin? xhoster@gmail.com
    Re: Can you detect that a process is waiting on stdin? <ben@morrow.me.uk>
    Re: Can you detect that a process is waiting on stdin? <nospam@somewhere.com>
        Get my IP address? <krahnj@telus.net>
    Re: Get my IP address? <ben@morrow.me.uk>
    Re: Get my IP address? <ben@morrow.me.uk>
        new CPAN modules on Sun Nov 25 2007 (Randal Schwartz)
        regex instead of a new lover. . . <ben.rogers@gmail.com>
    Re: union of 1 and 0 strings <krahnj@telus.net>
        waiting on recurively forked children <bernd.web@gmail.com>
    Re: waiting on recurively forked children <nobull67@gmail.com>
    Re: waiting on recurively forked children xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 24 Nov 2007 19:45:44 -0800 (PST)
From: mikexf@gmail.com
Subject: =?ISO-8859-1?Q?named_pipe_and_"Text_file_busy"?=
Message-Id: <c2fc3f0b-a880-4aa3-80a6-f6abbc7551f4@s6g2000prc.googlegroups.com>

Hi There,

I've got a PERL script which runs on linux and spawns a thread which
opens a FIFO pipe in read only mode. I use a different program to
write data to FIFO (written in c or simple echo command). Works like a
charm, however once I exit the script (via CTRL-C) and restart it, the
pipe becomes unusable for writing (i.e. no program is able to open it
for writing - they get back en error message: errno 26 "Text file
busy"). I need to create another FIFO in order for me use the script
again.
Internally I catch CTRL-C signal and close the FIFO explicitly.

What's wrong? Is it because I have 2 threads running i.e. one does
some other processing and the second one is responsible for the pipe??
What's the correct and clean way to exit from multithreaded program in
Perl?  Or is it another issue? Any help would be greatly appreciated.

Thanks, finpro









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

Date: Sun, 25 Nov 2007 04:57:49 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: =?ISO-8859-1?Q?named_pipe_and_"Text_file_busy"?=
Message-Id: <dvbn15-q8n1.ln1@osiris.mauzo.dyndns.org>


Quoth mikexf@gmail.com:
> 
> I've got a PERL

Perl. Spelling is important.

> script which runs on linux and spawns a thread which
> opens a FIFO pipe in read only mode. I use a different program to
> write data to FIFO (written in c or simple echo command). Works like a
> charm, however once I exit the script (via CTRL-C) and restart it, the
> pipe becomes unusable for writing (i.e. no program is able to open it
> for writing - they get back en error message: errno 26 "Text file
> busy"). I need to create another FIFO in order for me use the script
> again.

That's bizarre. Attempting to write to a pipe which isn't open for
reading should raise SIGPIPE, and if that is caught the write should
fail with EPIPE. Are you *sure* this is what's happening? What happens
if you run this Perl program to write to the pipe:

    #!/usr/bin/perl -l

    use strict;
    use warnings;

    use Errno;

    $SIG{PIPE} = sub { warn "got SIGPIPE" };

    open my $P, '>', 'pipe'
        or die "can't open pipe: $!";

    while (1) {
        print $P 'foo'
            or warn "print failed: $!";
        sleep 2;
    }

    __END__

> Internally I catch CTRL-C signal and close the FIFO explicitly.

This shouldn't make any difference: the fifo is closed when your program
exits anyway.

> What's wrong? Is it because I have 2 threads running i.e. one does
> some other processing and the second one is responsible for the pipe??

Again, shouldn't make any difference.

Ben



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

Date: 24 Nov 2007 23:53:29 GMT
From: xhoster@gmail.com
Subject: Re: Can you detect that a process is waiting on stdin?
Message-Id: <20071124185332.354$Au@newsreader.com>

"Thrill5" <nospam@somewhere.com> wrote:

> Is there some way that I can hook into STDIN and then detect when the CLI
> is waiting for input?  If this is possible, then all I need to do is send
> it a carriage return and it will then exit because not all the correct
> parameters were passed.

If the CLI is truly trying to read from STDIN, then if your perl program
closes stdin (or reopens it to /dev/null or whatever the Win32 equiv is)
before it starts the CLI, the program will inherit that STDIN and might
realize it has no real STDIN and so exit.  On the other hand, it might be
trying to read from a tty rather than STDIN.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Sun, 25 Nov 2007 00:47:22 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Can you detect that a process is waiting on stdin?
Message-Id: <q9tm15-g3i1.ln1@osiris.mauzo.dyndns.org>


Quoth xhoster@gmail.com:
> "Thrill5" <nospam@somewhere.com> wrote:
> 
> > Is there some way that I can hook into STDIN and then detect when the CLI
> > is waiting for input?  If this is possible, then all I need to do is send
> > it a carriage return and it will then exit because not all the correct
> > parameters were passed.
> 
> If the CLI is truly trying to read from STDIN, then if your perl program
> closes stdin (or reopens it to /dev/null or whatever the Win32 equiv is)

nul. As in C<system "prog <nul >file 2>file2";>. Yes, this means you
can't create a file called 'nul', in any directory. The DOS equivalent
of -d is C<if exist %DIR%\nul>. Bleech.

> before it starts the CLI, the program will inherit that STDIN and might
> realize it has no real STDIN and so exit.

Hmmm. Inheriting filehandles is a tricky business under Win32. It may be
worth using Win32::Process rather than system to have more control over
what's going on. I stringly suspect Windows won't let you start a
console process with a closed STDIN, and that a process that tries to
read from nul when it's not expecting to will not behave sensibly.

> On the other hand, it might be trying to read from a tty rather than
> STDIN.

No such thing under Win32. I *believe* a process can ask to talk to the
'current console', which is kinda-equivalent to opening /dev/tty,
though.

Ben



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

Date: Sun, 25 Nov 2007 01:44:14 -0500
From: "Thrill5" <nospam@somewhere.com>
Subject: Re: Can you detect that a process is waiting on stdin?
Message-Id: <74ednbWGHZIihNTanZ2dnUVZ_uGknZ2d@comcast.com>


"Ben Morrow" <ben@morrow.me.uk> wrote in message 
news:q9tm15-g3i1.ln1@osiris.mauzo.dyndns.org...
>
> Quoth xhoster@gmail.com:
>> "Thrill5" <nospam@somewhere.com> wrote:
>>
>> > Is there some way that I can hook into STDIN and then detect when the 
>> > CLI
>> > is waiting for input?  If this is possible, then all I need to do is 
>> > send
>> > it a carriage return and it will then exit because not all the correct
>> > parameters were passed.
>>
>> If the CLI is truly trying to read from STDIN, then if your perl program
>> closes stdin (or reopens it to /dev/null or whatever the Win32 equiv is)
>
> nul. As in C<system "prog <nul >file 2>file2";>. Yes, this means you
> can't create a file called 'nul', in any directory. The DOS equivalent
> of -d is C<if exist %DIR%\nul>. Bleech.
>
>> before it starts the CLI, the program will inherit that STDIN and might
>> realize it has no real STDIN and so exit.
>
> Hmmm. Inheriting filehandles is a tricky business under Win32. It may be
> worth using Win32::Process rather than system to have more control over
> what's going on. I stringly suspect Windows won't let you start a
> console process with a closed STDIN, and that a process that tries to
> read from nul when it's not expecting to will not behave sensibly.
>
>> On the other hand, it might be trying to read from a tty rather than
>> STDIN.
>
> No such thing under Win32. I *believe* a process can ask to talk to the
> 'current console', which is kinda-equivalent to opening /dev/tty,
> though.
>
> Ben
>

Thanks everyone for the replies and redirecting stdin from <nul worked like 
a charm!!! 




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

Date: Sun, 25 Nov 2007 03:57:41 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Get my IP address?
Message-Id: <4748F2A3.8B3E3BFD@telus.net>

$ perl -v

This is perl, v5.6.0 built for i586-linux

Copyright 1987-2000, Larry Wall

(Yes I know.  [My current machine is in the shop so I am stuck with this
old thing.])


I did an strace of ifconfig:

strace /sbin/ifconfig eth0
[ SNIP ]
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 6
[ SNIP ]
ioctl(6, SIOCGIFADDR, 0xbffff4ec)       = 0
ioctl(6, SIOCGIFDSTADDR, 0xbffff4ec)    = 0
ioctl(6, SIOCGIFBRDADDR, 0xbffff4ec)    = 0
ioctl(6, SIOCGIFNETMASK, 0xbffff4ec)    = 0


And I thought that this would be easy enough to do in Perl:

$ perl -le'
use Socket qw/PF_INET SOCK_DGRAM/;
require "linux/ioctl.ph";
my $proto = getprotobyname "ip";
socket SOCKET, PF_INET, SOCK_DGRAM, $proto or die "socket: $!";
defined( ioctl SOCKET, SIOCGIFADDR, my $address ) or die "ioctl: $!";
'
ioctl: No such device at -e line 6.


Is this just broken on 5.6.0 or does it work anywhere?  :-)



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 25 Nov 2007 06:00:44 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Get my IP address?
Message-Id: <clfn15-b2o1.ln1@osiris.mauzo.dyndns.org>


Quoth "John W. Krahn" <krahnj@telus.net>:
> 
> I did an strace of ifconfig:
> 
> strace /sbin/ifconfig eth0
> [ SNIP ]
> socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 6
> [ SNIP ]
> ioctl(6, SIOCGIFADDR, 0xbffff4ec)       = 0
> ioctl(6, SIOCGIFDSTADDR, 0xbffff4ec)    = 0
> ioctl(6, SIOCGIFBRDADDR, 0xbffff4ec)    = 0
> ioctl(6, SIOCGIFNETMASK, 0xbffff4ec)    = 0
> 
> And I thought that this would be easy enough to do in Perl:
> 
> $ perl -le'
> use Socket qw/PF_INET SOCK_DGRAM/;
> require "linux/ioctl.ph";
> my $proto = getprotobyname "ip";
> socket SOCKET, PF_INET, SOCK_DGRAM, $proto or die "socket: $!";
> defined( ioctl SOCKET, SIOCGIFADDR, my $address ) or die "ioctl: $!";

You need to give $address a string value at least as long as a struct
sockaddr, or you'll get a buffer overrun. ioctl can't create a value for
you: it doesn't know how long to make it.

> '
> ioctl: No such device at -e line 6.
> 
> Is this just broken on 5.6.0 or does it work anywhere?  :-)

You haven't said which network interface you're talking about; there
must be something else in that strace that binds the socket to a given
interface.

Ben



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

Date: Sun, 25 Nov 2007 06:43:11 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Get my IP address?
Message-Id: <v4in15-v9o1.ln1@osiris.mauzo.dyndns.org>

Sorry, scratch my last response. I (and you, I think) was completely
misunderstanding how SIOCGIFADDR is supposed to be called.

Quoth "John W. Krahn" <krahnj@telus.net>:
> 
> $ perl -le'
> use Socket qw/PF_INET SOCK_DGRAM/;
> require "linux/ioctl.ph";
> my $proto = getprotobyname "ip";
> socket SOCKET, PF_INET, SOCK_DGRAM, $proto or die "socket: $!";
> defined( ioctl SOCKET, SIOCGIFADDR, my $address ) or die "ioctl: $!";
> '
> ioctl: No such device at -e line 6.

You're calling it wrong :). SIOCGIFADDR takes a pointer to a struct
ifreq, which starts with an interface name. If you pass it an empty
string (which has an implicit "\0" at the end) then it's looking for an
interface with an empty name. Unsurprisingly, it can't find one :).

Under FreeBSD, with 5.8.8 or 5.6.0, this script

    #!/usr/bin/perl -l

    use Socket qw/PF_INET SOCK_DGRAM inet_ntoa sockaddr_in/;

    # h2ph gets SIOCGIFADDR wrong on my system.
    # Modern systems have complicated ioctl definitions that encode the
    # sizes of the types used, and h2ph can't cope.
    # h2ph is evil anyway. Use h2xs instead. ;)

    my $SIOCGIFADDR = 3223349537;

    # This is slightly daft... ip is protocol 0 by definition, and 0
    # means 'default protocol for this socket type', so you'll actually
    # get an ordinary UDP socket. IPPROTO_IP only really applies to
    # SOCK_RAW sockets.

    my $proto = getprotobyname 'ip';

    socket SOCKET, PF_INET, SOCK_DGRAM, $proto
        or die "socket: $!";

    # struct ifreq is 16 bytes of name, null-padded, followed by 16
    # bytes of answer. In the case of SIOCGIFADDR, that answer is a
    # packed address.

    my $ifreq = pack 'a32', 'xl0';
    ioctl SOCKET, $SIOCGIFADDR, $ifreq
        or die "ioctl: $!";

    my ($if, $sin)    = unpack 'a16 a16', $ifreq;
    my ($port, $addr) = sockaddr_in $sin;
    my $ip            = inet_ntoa $addr;

    print "addr: $ip";

    __END__

prints my ip address. You will of course need to change the value of
$SIOCGIFADDR (write a trivial bit of C to tell you what it should be)
and the interface name, and perhaps look up Linux' struct ifreq and
change the unpack format (it's probably the same though).

Now do it properly with Net::Interface :).

Ben



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

Date: Sun, 25 Nov 2007 05:42:14 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Nov 25 2007
Message-Id: <Js1ruE.Dqx@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.

App-sync_cpantesters-0.02
http://search.cpan.org/~marcel/App-sync_cpantesters-0.02/
Sync CPAN testers failure reports to local dir 
----
App-sync_cpantesters-0.03
http://search.cpan.org/~marcel/App-sync_cpantesters-0.03/
Sync CPAN testers failure reports to local dir 
----
App-sync_cpantesters-0.04
http://search.cpan.org/~marcel/App-sync_cpantesters-0.04/
Sync CPAN testers failure reports to local dir 
----
Bundle-MARCEL-0.05
http://search.cpan.org/~marcel/Bundle-MARCEL-0.05/
install (nearly) all modules by MARCEL 
----
Bundle-MARCEL-Likes-0.02
http://search.cpan.org/~marcel/Bundle-MARCEL-Likes-0.02/
Some modules I like to have around 
----
CatalystX-CRUD-0.14
http://search.cpan.org/~karman/CatalystX-CRUD-0.14/
CRUD framework for Catalyst applications 
----
CatalystX-CRUD-0.15
http://search.cpan.org/~karman/CatalystX-CRUD-0.15/
CRUD framework for Catalyst applications 
----
Class-MOP-0.47
http://search.cpan.org/~stevan/Class-MOP-0.47/
A Meta Object Protocol for Perl 5 
----
Class-Null-1.09
http://search.cpan.org/~marcel/Class-Null-1.09/
Implements the Null Class design pattern 
----
Class-Std-Utils-v0.0.3
http://search.cpan.org/~dmuey/Class-Std-Utils-v0.0.3/
Utility subroutines for building "inside-out" objects 
----
Class-Value-0.04
http://search.cpan.org/~marcel/Class-Value-0.04/
the Value Object design pattern 
----
Config-General-2.37
http://search.cpan.org/~tlinden/Config-General-2.37/
Generic Config Module 
----
Data-Timeline-0.02
http://search.cpan.org/~marcel/Data-Timeline-0.02/
Timelines 
----
Data-Timeline-IScrobbler-0.02
http://search.cpan.org/~marcel/Data-Timeline-IScrobbler-0.02/
Build a timeline from tracks recorded by iScrobbler 
----
Data-Timeline-SVK-0.02
http://search.cpan.org/~marcel/Data-Timeline-SVK-0.02/
Builds a timeline from an 'svk log' 
----
DateTime-Format-Natural-0.61
http://search.cpan.org/~schubiger/DateTime-Format-Natural-0.61/
Create machine readable date/time with natural parsing logic 
----
Devel-sdb-0.01
http://search.cpan.org/~kraman/Devel-sdb-0.01/
Smart Debugger 
----
Digest-MD5-File-0.06
http://search.cpan.org/~dmuey/Digest-MD5-File-0.06/
Perl extension for getting MD5 sums for files and urls. 
----
Dist-Joseki-0.11
http://search.cpan.org/~marcel/Dist-Joseki-0.11/
tools for the prolific module author 
----
File-Path-2.04
http://search.cpan.org/~dland/File-Path-2.04/
Create or remove directory trees 
----
File-Stata-DtaReader-0.3
http://search.cpan.org/~reckon/File-Stata-DtaReader-0.3/
CPAN release history 
----
GPS-Babel-0.10
http://search.cpan.org/~andya/GPS-Babel-0.10/
Perl interface to gpsbabel 
----
Games-Go-Coordinate-0.03
http://search.cpan.org/~marcel/Games-Go-Coordinate-0.03/
represents a board coordinate in the game of Go 
----
Games-Go-Rank-0.04
http://search.cpan.org/~marcel/Games-Go-Rank-0.04/
represents a player's rank in the game of Go 
----
Glib-EV-0.1
http://search.cpan.org/~mlehmann/Glib-EV-0.1/
Coerce Glib into using the EV module as event loop. 
----
HTML-SimpleLinkExtor-1.18
http://search.cpan.org/~bdfoy/HTML-SimpleLinkExtor-1.18/
Extract links from HTML 
----
HTTP-SimpleLinkChecker-1.14
http://search.cpan.org/~bdfoy/HTTP-SimpleLinkChecker-1.14/
Check the HTTP response code for a link 
----
LWP-UserAgent-ProgressBar-0.01
http://search.cpan.org/~marcel/LWP-UserAgent-ProgressBar-0.01/
An LWP user agent that can display a progress bar 
----
Mac-PropertyList-SAX-0.64
http://search.cpan.org/~kulp/Mac-PropertyList-SAX-0.64/
work with Mac plists at a low level, fast 
----
Mail-SpamCannibal-0.83
http://search.cpan.org/~miker/Mail-SpamCannibal-0.83/
A tool to stop SPAM 
----
MooseX-AttributeHelpers-0.05
http://search.cpan.org/~stevan/MooseX-AttributeHelpers-0.05/
Extend your attribute interfaces 
----
MooseX-ClassAttribute-0.01
http://search.cpan.org/~drolsky/MooseX-ClassAttribute-0.01/
Declare class attributes Moose-style 
----
Net-Address-Ethernet-1.102
http://search.cpan.org/~mthurn/Net-Address-Ethernet-1.102/
find hardware ethernet address 
----
POE-Component-SmokeBox-Recent-0.01
http://search.cpan.org/~bingos/POE-Component-SmokeBox-Recent-0.01/
A POE component to retrieve recent CPAN uploads. 
----
Proc-Simple-Async-0.02
http://search.cpan.org/~berle/Proc-Simple-Async-0.02/
Keyword sugar for Proc::Simple 
----
Rose-DBx-Garden-0.06
http://search.cpan.org/~karman/Rose-DBx-Garden-0.06/
bootstrap Rose::DB::Object and Rose::HTML::Form classes 
----
Set-CrossProduct-1.93
http://search.cpan.org/~bdfoy/Set-CrossProduct-1.93/
work with the cross product of two or more sets 
----
String-BlackWhiteList-0.04
http://search.cpan.org/~marcel/String-BlackWhiteList-0.04/
match a string against a blacklist and a whitelist 
----
String-FlexMatch-0.11
http://search.cpan.org/~marcel/String-FlexMatch-0.11/
flexible ways to match a string 
----
String-LCSS_XS-0.4
http://search.cpan.org/~limaone/String-LCSS_XS-0.4/
Find The Longest Common Substring of Two Strings. 
----
Symantec-PCAnywhere-Profile-0.06
http://search.cpan.org/~kulp/Symantec-PCAnywhere-Profile-0.06/
Base class for pcAnywhere utility functions 
----
Test-Virtual-Filesystem-0.07
http://search.cpan.org/~cdolan/Test-Virtual-Filesystem-0.07/
Validate a filesystem 
----
Text-MultiMarkdown-1.0.2
http://search.cpan.org/~kulp/Text-MultiMarkdown-1.0.2/
Convert MultiMarkdown syntax to (X)HTML 
----
Text-MultiMarkdown-1.0.3
http://search.cpan.org/~kulp/Text-MultiMarkdown-1.0.3/
Convert MultiMarkdown syntax to (X)HTML 
----
Text-Pipe-0.05
http://search.cpan.org/~marcel/Text-Pipe-0.05/
Common text filter API 
----
Text-UpsideDown-0.02
http://search.cpan.org/~marcel/Text-UpsideDown-0.02/
flip text upside-down using Unicode 
----
UNIVERSAL-isa-1.00_00
http://search.cpan.org/~chromatic/UNIVERSAL-isa-1.00_00/
Attempt to recover from people calling UNIVERSAL::isa as a function 
----
WWW-Mechanize-Plugin-JavaScript-0.001
http://search.cpan.org/~sprout/WWW-Mechanize-Plugin-JavaScript-0.001/
JavaScript plugin for WWW::Mechanize 
----
WWW-NicoVideo-0.01
http://search.cpan.org/~hirata/WWW-NicoVideo-0.01/
Perl interface to Nico Nico Video service 
----
Weather-Com-0.5.3
http://search.cpan.org/~schnueck/Weather-Com-0.5.3/
fetching weather information from *weather.com* 
----
Web-Scraper-0.23
http://search.cpan.org/~miyagawa/Web-Scraper-0.23/
Web Scraping Toolkit inspired by Scrapi 
----
XML-Compile-0.60
http://search.cpan.org/~markov/XML-Compile-0.60/
Compilation based XML processing 
----
XML-Compile-SOAP-0.63
http://search.cpan.org/~markov/XML-Compile-SOAP-0.63/
base-class for SOAP implementations 


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/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 24 Nov 2007 23:47:11 -0800 (PST)
From: aardvarkman <ben.rogers@gmail.com>
Subject: regex instead of a new lover. . .
Message-Id: <731f27bf-ea26-4854-866d-3e5bb08ee320@a39g2000pre.googlegroups.com>

Well, I'd rather get ahold of anusha and forget this whole business,
but I guess I should finish this first:

I have a config file that get read by my main script. A sub parses the
file and does just fine under simple circumstances. It finds all
this:

Index directory === C:/
HTML resource directory === C:/Aardvark/res/user_html/test_index
HTML resources === *.html *.htm
File types to index === html|htm|pdf|xml|zip|mif|txt

# Frame template options:

Template directory === C:/Aardvark/res/frame_templates
Template types === *.fm
Template objects === Para,Char,XRefs,Vars,Tables,Page Layouts,Math
Defs,Ref Pages,Conditions

I get the values on both sides of the ===.

The problem is that when there is a . or  ? (and maybe other things)
it fails:

# Stuff I can't read
Title rule choices === title.fm
TOC rule choices === TOC.fm
Appendix rule choices === apx.fm
Index rule choices === IOM.fm|IX.fm
Body rule choices === Everything else!
Other rule choices 1 === ????????
Other rule choices 2 === ????????

What I am looking for is a regex that finds anything one line at a
time separated by ===. In other words, all my config options are on a
single line like: key === value.

I started guessing, then started researching, and now I ask the
experts: what will work?

Stuff I tried:

    while(<$fh>){
        if (/#########/){
            last;
        } # todo: make this match . and ?
       elsif (/^\ *(.*?)\ *===\ *(.*?)\ *$/){ # original
       # elsif (/^\ *(.*?)\ *===\ *(.*?)\ *$/sm){
       # elsif (/\A\ *(.*?)\ *===\ *(.*?)\ *\Z/sm){
       # elsif (/^ *(.*?) *=== *(.*?) *$/){
       # elsif (/^ *(.*?) *=== *(.*?) *$/sm){
       # elsif (/^\ *(.*?)\ *===\ *(.*?)$/is){
       # elsif (/^(.*?)===(.*?)$/){
       # elsif (/^\s+(.*?)\s+$===^\s+(.*?)\s+$/) {
       # elsif (/^\s+(.*?)\s+$===^\s+(.*?)\s+$/m) {
       # elsif (/^(.*?) === (.*?)$/sm) {
                   $items -> {$1} = $2;
        }
    }
    return $items;


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

Date: Sun, 25 Nov 2007 03:36:28 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: union of 1 and 0 strings
Message-Id: <4748EDA9.AC54CAEA@telus.net>

"avilella@gmail.com" wrote:
> 
> I have two strings:
> 
>   DB<32> x $seqchoice
> 0  '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 1 0 0 '
>   DB<33> x $outgroup
> 0  '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 1 0 '
> 
> and I want to make the "union" of the "ones" in $outgroup to
> $seqchoice, so that I end up with:
> 
>   DB<32> x $seqchoice
> 0  '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 0 '
>   DB<33> x $outgroup
> 0  '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 1 0 '
> 
> notice the "1" in the penultimate position in $seqchoice.
> 
> Any ideas of a regexp that would do for me?

No need for a regexp:

$ perl -le'
$seqchoice = q[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 0 0 ];
$outgroup  = q[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 ];
print $seqchoice | $outgroup;
'
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 


Is a string the best data structure for your needs?

perldoc -f vec



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 24 Nov 2007 13:34:04 -0800 (PST)
From: "bernd.web@gmail.com" <bernd.web@gmail.com>
Subject: waiting on recurively forked children
Message-Id: <fa6b5848-6016-42ef-8424-71d3b7ce6301@e10g2000prf.googlegroups.com>

Hi all,

I am trying to wait like the bash '"wait" on all my forked processes.
A recursive routine that forked off children is called from main.
Using `ps` polling I managed to accomplish this, but how to use "wait"
to wait for (great)grandchildren in the original parent without
waiting during the recursion?
I would not like to wait for completion of children in the recursion
but only in the main.
However, I have not been able to figure out how to do this.
I did have a look at:
  http://perldoc.perl.org/perlipc.html#Signals
  http://perldoc.perl.org/perlfaq8.html


Has anyone ideas?

do_fork(1);
#continue when all children, and the children of the children etc...
are finished
print "All sub processes completed\n";

sub do_fork {
   #fork off children
   my $depth = shift;
   if ($depth < 10) {
   for(my $i = 0; $i < 4; $i++) {
   unless ( fork ) {
          #do something......
           do_fork($depth + 1);
           exit;
    }
}

Kind regards,
Bernd


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

Date: Sat, 24 Nov 2007 13:51:22 -0800 (PST)
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: waiting on recurively forked children
Message-Id: <23f79e60-d6b1-4fb0-bb8d-49eaeb873a1b@o6g2000hsd.googlegroups.com>

On Nov 24, 9:34 pm, "bernd....@gmail.com" <bernd....@gmail.com> wrote:
> Hi all,
>
> I am trying to wait like the bash '"wait" on all my forked processes

> A recursive routine that forked off children is called from main.
> Using `ps` polling I managed to accomplish this, but how to use "wait"
> to wait for (great)grandchildren in the original parent without
> waiting during the recursion?
> I would not like to wait for completion of children in the recursion
> but only in the main.
> However, I have not been able to figure out how to do this.
> I did have a look at:

I do not believe it is possible as such. Orphaned grandchildren are
adopted by process 1. You can't  be informed of their demise.

This has nothing to do with Perl.

Perhaps you should use a FIFO. If each descendant inherits a copy of
the writing end the you can simply wait for EOF on the reading end.

Actually there may be some tricks with process groups or some-such,
but like I said this is not related to Perl.


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

Date: 25 Nov 2007 00:14:10 GMT
From: xhoster@gmail.com
Subject: Re: waiting on recurively forked children
Message-Id: <20071124191413.132$5i@newsreader.com>

"bernd.web@gmail.com" <bernd.web@gmail.com> wrote:
> Hi all,
>
> I am trying to wait like the bash '"wait" on all my forked processes.

On my bash, wait doesn't do what you describe.  It doesn't wait for
orphaned grand-children, or at least not in general.


> A recursive routine that forked off children is called from main.
> Using `ps` polling I managed to accomplish this, but how to use "wait"
> to wait for (great)grandchildren in the original parent without
> waiting during the recursion?
> I would not like to wait for completion of children in the recursion
> but only in the main.

Why?

> However, I have not been able to figure out how to do this.
> I did have a look at:
>   http://perldoc.perl.org/perlipc.html#Signals
>   http://perldoc.perl.org/perlfaq8.html
>
> Has anyone ideas?

You could have the children take out shared locks on one file.  The
uberparent waits to get an exclusive lock.  When it obtains it, all the
children must be gone.  Or you could make all the children share the write
end of a pipe or socket.  When the read end in the uberparent becomes
readable (eof), all the children have exited.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

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


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