[25715] in Perl-Users-Digest
Perl-Users Digest, Issue: 7955 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 8 11:05:52 2005
Date: Fri, 8 Apr 2005 08:05:16 -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 Fri, 8 Apr 2005 Volume: 10 Number: 7955
Today's topics:
Re: A menu using framebuffer (Anno Siegel)
Re: asynchronous system shell? <Ninja67@gmail.com>
Re: Basic Regular Expressions question... <tassilo.von.parseval@rwth-aachen.de>
Re: Basic Regular Expressions question... (Anno Siegel)
Re: Basic Regular Expressions question... (Anno Siegel)
Re: Help with regular expression (Anno Siegel)
Not able to connect to oracle db using DBI ( Activestat debhatta@hotmail.com
Re: Not able to connect to oracle db using DBI ( Active <mothra@nowhereatall.com>
Re: Not able to connect to oracle db using DBI ( Active <dave@sackheads.org>
param verification: is a handle? <a-sicken@web.de>
Re: param verification: is a handle? <bernard.el-haginDODGE_THIS@lido-tech.net>
Perl on Rails? <nospam@bigpond.com>
Re: Perl on Rails? <1usa@llenroc.ude.invalid>
Re: Perl script hangs <joe@inwap.com>
Re: Q: // and "magic" <joe@inwap.com>
update: timezone offset calc and date formatting <leendert@wouter.unitedknowledge.net>
Re: Windows fork emulation (and buffering?) problem <henry.townsend@not.here>
Re: Windows fork emulation (and buffering?) problem <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Apr 2005 08:59:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A menu using framebuffer
Message-Id: <d35h4m$rdt$4@mamenchi.zrz.TU-Berlin.DE>
<aulne2002@yahoo.ca> wrote in comp.lang.perl.misc:
> Hi all,
>
> Is it possible at all to build a graphical menu system without X,
> using Perl and modules ? I mean, is there some high-level toolkit
> (module) for Perl that offers dialog boxes, windows, etc, needed for
> menus ? Context is, after booting from a USB key, a graphical menu
> proposes the user some choices.
>
> Is this (easily) possible with Perl at all ?
Check out Curses::UI on CPAN.
Anno
------------------------------
Date: 8 Apr 2005 06:36:43 -0700
From: "Ninja67" <Ninja67@gmail.com>
Subject: Re: asynchronous system shell?
Message-Id: <1112967403.646959.6780@z14g2000cwz.googlegroups.com>
Joe Smith wrote:
> Ninja67 wrote:
>
> >>Add an "&" to the end. see:
> >>perldoc -q background.
> >
> > That worked! You're a genius! Now that sure was easy. I wonder
why
> > it was so hard to find anything on that.
>
> Hard to find?
>
> perldoc -f system
> system LIST
> Does exactly the same thing as "exec LIST", except that a
fork
> is done first, and the parent process waits for the child
pro-
> cess to complete. Note that argument processing varies
depend-
> ing on the number of arguments. If there is more than one
> argument in LIST, or if LIST is an array with more than one
> value, starts the program given by the first element of the
> list with arguments given by the rest of the list. If there
is
> only one scalar argument, the argument is checked for shell
> metacharacters, and if there are any, the entire argument is
> passed to the system's command shell for parsing (this is
> "/bin/sh -c" on Unix platforms, but varies on other
platforms).
>
> That last line implies that you should look at the manual for the
> Bourne shell to see how /bin/sh will handle the LIST. Since you
> are using "2>/dev/null" is it obvious that you are at least
> somewhat familiar with Bourne shell metacharacters.
>
> -Joe
Thanks Joe, that's great information. You made one incorrect
assumption however. Although 99% of the perl script is written by me,
the system call was inherited from another program. I have *no idea*
what 2>/dev/null does. All I know is that without it, things weren't
working so I left it in. I probably should research what that portion
of the call actually means, but with other priorities in the way, I
took a "it's not broke so don't fix it" approach.
Thanks again.
------------------------------
Date: Fri, 8 Apr 2005 09:52:23 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Basic Regular Expressions question...
Message-Id: <slrnd5ce1n.1sv.tassilo.von.parseval@localhost.localdomain>
Also sprach Anno Siegel:
> John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
>> Anno Siegel wrote:
>> > Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
>
> [using index() instead of s///]
>
>> > my $i = length $thisPage;
>> > substr( $thisPage, $i, length $find) = $replace while
>> > ( $i = rindex $thisPage, $find, $i) >= 0;
>> >
>> > That way only the unchanged part of the string is ever searched.
>>
>> Also, using the four argument substr() should be faster.
>
> How so? I never heard of that.
John is right according to a benchmark:
#!/usr/bin/perl -w
use strict;
use Benchmark qw/cmpthese/;
my $string = "0" x 100;
cmpthese(-2, {
arg4 => sub {
substr $string, rand length $string, 1, "0";
},
arg3 => sub {
substr($string, rand length $string, 1) = "0";
},
});
__END__
Rate arg3 arg4
arg3 512250/s -- -43%
arg4 903253/s 76% --
The reason for arg4 being faster is the fact that perl needs to attach
magic to the return value of the 3-argument substr(). In the 4-argument
case this is not the case.
> I use "=" with substr() assignments because it reads better. Four argument
> substr is for when I need the old value of the substring too.
In most cases though the argument of readability supersedes speed, so
now you're right. :-)
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: 8 Apr 2005 08:39:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Basic Regular Expressions question...
Message-Id: <d35fvs$rdt$2@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
> > John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> >> Also, using the four argument substr() should be faster.
> >
> > How so? I never heard of that.
>
> John is right according to a benchmark:
Yup. I ran one too. The difference is significant.
> The reason for arg4 being faster is the fact that perl needs to attach
> magic to the return value of the 3-argument substr(). In the 4-argument
> case this is not the case.
Ah... the return value from 4-arg substr is indeed not magic:
my $x = 'aaaaabbbbbcccc';
my $ref = \ substr( $x, 5, 5, 'ZZZZZ');
$$ref = 'XXXXX'; # has no effect on $x
print "$x\n"; # aaaaaZZZZZcccc
After removing the fourth argument from substr(), $x changes to
"aaaaaXXXXXcccc".
Live and learn.
Anno
------------------------------
Date: 8 Apr 2005 08:39:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Basic Regular Expressions question...
Message-Id: <d35g0i$rdt$3@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
> > John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> >> Also, using the four argument substr() should be faster.
> >
> > How so? I never heard of that.
>
> John is right according to a benchmark:
Yup. I ran one too. The difference is significant.
> The reason for arg4 being faster is the fact that perl needs to attach
> magic to the return value of the 3-argument substr(). In the 4-argument
> case this is not the case.
Ah... the return value from 4-arg substr is indeed not magic:
my $x = 'aaaaabbbbbcccc';
my $ref = \ substr( $x, 5, 5, 'ZZZZZ');
$$ref = 'XXXXX'; # has no effect on $x
print "$x\n"; # aaaaaZZZZZcccc
After removing the fourth argument from substr(), $x changes to
"aaaaaXXXXXcccc".
Live and learn.
Anno
------------------------------
Date: 8 Apr 2005 09:18:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help with regular expression
Message-Id: <d35i8h$rdt$5@mamenchi.zrz.TU-Berlin.DE>
Steven Kuo <skuo@mtwhitney.nsc.com> wrote in comp.lang.perl.misc:
> On 7 Apr 2005 soup_or_power@yahoo.com wrote:
>
> > I need help with this regex. It looks the keys of fdat are searched for
> > "$prefix" and fdat hash is deleted. I have no idea what the map is
> > trying to do. Thanks for your help.
> >
> > debug my %indices = map { (/^\Q$prefix.\E(.+)/), $_ } grep { delete
> > $fdat{$_} } grep /^\Q$prefix.\E/, keys %fdat;
>
>
>
> That's likely to be wrong as 'map' may return an odd number of elements
How? The first grep (chronologically, so textually the last one) makes
sure that /^\Q$prefix.\E/ will always match, so the map block will
always return exactly two elements.
I agree that the operation could be better written.
Anno
------------------------------
Date: 8 Apr 2005 06:02:49 -0700
From: debhatta@hotmail.com
Subject: Not able to connect to oracle db using DBI ( Activestate )
Message-Id: <1112965369.409586.252140@f14g2000cwb.googlegroups.com>
Hi all,
I have a script like :
use strict;
use DBI;
my $con;
$con = DBI->connect("dbi:Oracle:hrdrel","hr","hr") or die "It cannot be
done";
When I am running it the error is :
install_driver(Oracle) failed: Can't locate DBD/Oracle.pm in @INC (@INC
contain
: D:/Perl/lib D:/Perl/site/lib .) at (eval 1) line 3.
Perhaps the DBD::Oracle perl module hasn't been fully installed,
or perhaps the capitalisation of 'Oracle' isn't right.
Available drivers: ADO, Chart, DBM, ExampleP, File, ODBC, Proxy,
Sponge.
at example.pl line 7
Now I am using Activestate perl, and have installed the DBI module
using PPM. But I am feeling that above error is due to some other
module missing. Can anyone kindly guide me to the correct one or any
help on the above issue?
Following are some of the modules installed here:
ppm> query *D*
Querying target 1 (ActivePerl 5.8.6.811)
1. ActivePerl-DocTools [0.04] Perl extension for Documentation TOC
Generat~
2. Apache-DBI [0.94] Initiate a persistent database
connection
3. Class-Data-Inherita~ [0.02] Inheritable, overridable class data
4. Class-DBI [0.96] Simple Database Abstraction
5. Class-DBI-Oracle [0.51] Extensions to Class::DBI for Oracle
6. Data-Dump [1.06] Pretty printing of data structures
7. DBD-ADO [2.94] A DBI driver for Microsoft ADO
(Active Data ~
8. DBD-Chart [0.80] DBI driver abstraction for Rendering
Charts ~
9. DBD-ODBC [1.11] ODBC Driver for DBI
10. DBI [1.48] Database independent interface for
Perl
11. DBIx-ContextualFetch [1.02] Add contextual fetches to DBI
12. Digest-HMAC [1.01] Keyed-Hashing for Message
Authentication
13. Digest-MD2 [2.03] Perl interface to the MD2 Algorithm
14. Digest-SHA1 [2.10] Perl interface to the SHA-1 Algorithm
15. Ima-DBI [0.33] Database connection caching and
organization
16. MD5 [2.03] Perl interface to the MD5 Algorithm
(obsolet~
ppm>
ppm> search *oracle*
Searching in Active Repositories
1. Class-DBI-Oracle [0.51] Extensions to Class::DBI for Oracle
2. DBIx-OracleLogin [0.02] takes a string and splits out individual
login in~
3. Oracle-Trace [1.06] Perl Module for parsing Oracle Trace files
ppm>
P.S - I am sorry if Activestate Perl Qustions are not to be asked in
this forum.
------------------------------
Date: Fri, 8 Apr 2005 06:59:31 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Not able to connect to oracle db using DBI ( Activestate )
Message-Id: <42568d3c$1@usenet.ugs.com>
Hello,
<debhatta@hotmail.com> wrote in message
news:1112965369.409586.252140@f14g2000cwb.googlegroups.com...
> Hi all,
>
(snipped)
> install_driver(Oracle) failed: Can't locate DBD/Oracle.pm in @INC (@INC
> contain
(more snippage)
PPM interactive shell (2.1.6) - type 'help' for available commands.
PPM> search DBD-Oracle
^^^^^^^^^^^^^^^^^^^^^
Packages available from
http://ppm.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer:
DBD-Oracle [1.12] Oracle database driver for the DBI module
I hope this helps
Mothra
------------------------------
Date: Fri, 8 Apr 2005 14:00:42 +0000 (UTC)
From: Dave Peacock <dave@sackheads.org>
Subject: Re: Not able to connect to oracle db using DBI ( Activestate )
Message-Id: <slrnd5d3ka.43s.dave@david-peacocks-computer.local>
> debhatta@hotmail.com wrote:
<snip>
> When I am running it the error is :
>
> install_driver(Oracle) failed: Can't locate DBD/Oracle.pm in @INC (@INC
> contain
>: D:/Perl/lib D:/Perl/site/lib .) at (eval 1) line 3.
> Perhaps the DBD::Oracle perl module hasn't been fully installed,
> or perhaps the capitalisation of 'Oracle' isn't right.
> Available drivers: ADO, Chart, DBM, ExampleP, File, ODBC, Proxy,
> Sponge.
> at example.pl line 7
I would hazard a guess that the DBD::Oracle module isn't installed.
> Now I am using Activestate perl, and have installed the DBI module
> using PPM. But I am feeling that above error is due to some other
> module missing. Can anyone kindly guide me to the correct one or any
> help on the above issue?
DBI is just part of the equation. You're on the right track.
> Following are some of the modules installed here:
>
> ppm> query *D*
<snip>
FX: <scans list>
I don't see DBD::Oracle in that list. You need to install it.
You're confusion comes from the fact that DBI is a generic interface
for the DBD's. You also need to install which ever driver you need
for the databases you'll be accessing.
--
Dave Peacock - dave@sackheads.org
------------------------------
Date: Fri, 08 Apr 2005 13:24:31 +0200
From: "A. Sicken" <a-sicken@web.de>
Subject: param verification: is a handle?
Message-Id: <d35plf$d2pog$1@hades.rz.uni-saarland.de>
Hello,
I have to handle follwing problem: A class method can be called with an
argument, which can be
a) a simple filename
b) a glob (perls default file handles)
c) a reference to a glob (IO::Handle object for example)
How do I verify the argument? Or where can I find an example how to do
it?
In advance, thanx
AndSi
--
PGP-Key: 875F5C96
------------------------------
Date: Fri, 8 Apr 2005 13:38:15 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: param verification: is a handle?
Message-Id: <Xns96328ABA8FC8Delhber1lidotechnet@62.89.127.66>
"A. Sicken" <a-sicken@web.de> wrote:
> Hello,
>
> I have to handle follwing problem: A class method can be called
> with an argument, which can be
> a) a simple filename
> b) a glob (perls default file handles)
> c) a reference to a glob (IO::Handle object for example)
>
> How do I verify the argument? Or where can I find an example how
> to do it?
perldoc -f ref
--
Cheers,
Bernard
------------------------------
Date: Fri, 08 Apr 2005 20:40:12 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Perl on Rails?
Message-Id: <42565f7d_2@x-privat.org>
I've been playing around with Ruby of Rails for a day so I wonder if
somebody has been working on a Perl equivalent.
It consists of
- an application generator, which generates for web front end to a
relational database.
Basic add/insert/delete web forms are generated by default, and you can add
your own logic as classes.
- automatic object-relations mapping. Database tables are seen as objects
inside the framework.
- automated data modelling eg you can specify 1:many relationships & the
code is automaticly generated
HTML::Mason would appear to do a lot less than this.
gtoomey
------------------------------
Date: Fri, 08 Apr 2005 12:39:40 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl on Rails?
Message-Id: <Xns9632580C12B2Casu1cornelledu@127.0.0.1>
Gregory Toomey <nospam@bigpond.com> wrote in
news:42565f7d_2@x-privat.org:
> I've been playing around with Ruby of Rails for a day so I wonder if
> somebody has been working on a Perl equivalent.
>
> It consists of
> - an application generator, which generates for web front end to a
> relational database.
> Basic add/insert/delete web forms are generated by default, and you
> can add your own logic as classes.
> - automatic object-relations mapping. Database tables are seen as
> objects inside the framework.
> - automated data modelling eg you can specify 1:many relationships &
> the code is automaticly generated
>
> HTML::Mason would appear to do a lot less than this.
I have never used Mason, so I can't comment on that.
However, at least part of the functionality can be obtained by using
CGI::Application, HTML::Template, Class::DBI, Class::DBI::AsForm,
Class::DBI::FromCGI etc.
AFAIK, Randal Schwartz just put together CGI::Prototype, but I haven't
had a chance to try it.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Fri, 08 Apr 2005 01:46:54 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Perl script hangs
Message-Id: <H5ydndLWdOic2MvfRVn-hA@comcast.com>
Kurt wrote:
> while ($array[$counter])
> {
> ...
> if (some_statement)
> {
> ...
> $counter++;
> }
> }
On the other hand, if $counter needs to always be incremented,
you could re-arrange the loop to:
while ($counter < @array and $array[$counter]) {
...
next unless some_statement;
...
} continue {
$counter++;
}
-Joe
------------------------------
Date: Fri, 08 Apr 2005 01:28:59 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Q: // and "magic"
Message-Id: <BdWdnUpHWbRT3cvfRVn-tQ@comcast.com>
xhoster@gmail.com wrote:
>> If the PATTERN evaluates to the empty string, the last
>> *successfully* matched regular expression is used instead. In
>> this case, only the "g" and "c" flags on the empty pattern is
>> honoured - the other flags are taken from the original pattern.
>> If no match has previously succeeded, this will (silently) act
>> instead as a genuine empty pattern (which will always match).
>
> So, does anyone find this behavior useful? I've never intentionally used
> it, and I can't imagine doing so in the future.
That's the way vi works. (And jove but not emacs.)
-Joe
------------------------------
Date: Fri, 08 Apr 2005 12:32:35 +0200
From: "Leendert Bottelberghs" <leendert@wouter.unitedknowledge.net>
Subject: update: timezone offset calc and date formatting
Message-Id: <pan.2005.04.08.10.32.35.494557@wouter.unitedknowledge.net>
Hi all,
a few days ago I posted on this list about timezone offset calculations.
After some suggestions, I both tested with the use of some Date modules,
as rewrote my own routine for calcutating the time offset and formatting a
date-time string. Benchmark tests show that my own routine is about 8000%
(!!!) faster than using the Date::Manip module. This is especially
interesting when you have to format dates at a high rate, such as for
http-logging. I'll elaborate some more on my findings in this post.
I need a formatted date-time string for a mod_perl module that writes
access logs. Apache uses it's own date format, which includes the timezone
offset. As a log entry is written for every request, and thus the date
format has to be calculated for every request, I want it's overhead to be
minimal.
I wanted to test two different modules for date formatting and calcs. I
tried to install the - very complete - module DateTime. But for some
reasons it wouldn't install on my system. Besides the fact that it is very
complete, it also seemed like to be a bit over-the-top for what I needed.
I succeeded in using Date::Manip for constructing the date-format string,
which looks like: [08/Apr/2005:11:24:03 +0100]. The code for constructing
this string is fairly simple and concise:
<code>
sub DateManip {
my $time = &UnixDate("today", "[%d/%b/%Y:%H:%M:%S %z]"); return $time;
}
</code>
Where as my own routine is a bit more complex:
<code>
sub homeBrew {
my @lctime = localtime();
my @gmtime = gmtime();
my $mo = (($lctime[2]-$gmtime[2])%24)*60+($lctime[1]-$gmtime[1])%60;
my $tz = int($mo/60)*100+($mo/abs($mo))*($mo%60);
my $time = sprintf "[%02d/%3s/%4d:%02d:%02d:%02d %+05d]",
($lctime[3],
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$lctime[4]]),
(1900+$lctime[5]),
$lctime[2],
$lctime[1],
$lctime[0],
$tz);
return $time;
}
</code>
The main calculations are for the timezone difference. I used Benchmark to
measure the performace of both routines, and here are the results (P4
2GHz):
Benchmark: running DateManip, homeBrew for at least 10 CPU seconds...
DateManip: 10 wallclock secs (10.46 usr + 0.02 sys = 10.48 CPU) @
280.34/s (n=2938)
homeBrew: 11 wallclock secs ( 9.74 usr + 0.32 sys = 10.06 CPU) @
22500.00/s (n=226350)
Rate DateManip homeBrew
DateManip 280/s -- -99% homeBrew 22500/s 7926%
--
I'd say that is quite a difference! Since I want to use this on a
webserver, where a probable 100-300 requests/second arrive, I don't want
my CPU to be fully occupied formatting a date.
The main performance gain is in the algorithm for calculating the timezone
offset. In the previous discussion, "Geoff" pointed out, that timezone
offset is not always in full hours, but can also differ 30 minutes. He
suggested calculating the difference in seconds. So I did, using
Time::Local to convert localtime() and gmtime() to seconds. After
calculating the difference in seconds, I have to convert it back to hours
and minutes in order to get the proper format. This converting was
obviously CPU-consuming, as this routine was approx. 15x slower than the
algorithm used in the current routine. This algorithm works as follows: 1.
calculate hour difference:
a = (localtime(hours) - gmtime(hours))%24
2. convert these hours to minutes:
b = a*60
3. calculate the minute difference:
c = (localtime(minutes) - gmtime(minutes))%60
4. sum to get the total time diff in minutes:
d = b + c
5. prepare to format to 4 digit hhmm number:
e = int(d/60)*100+(d/abs(d))*(d%60)
To demonstrate the efficiency of using this algorithm in stead of the
Date::Manip method, I did another test where I only formatted the
time-zone offset. The routines:
<code>
sub homeBrew {
my @lctime = localtime();
my @gmtime = gmtime();
my $mo = (($lctime[2]-$gmtime[2])%24)*60+($lctime[1]-$gmtime[1])%60;
my $tz = int($mo/60)*100+($mo/abs($mo))*($mo%60);
my $time = sprintf "%+05d", $tz;
return $time;
}
}
sub DateManip {
my $time = &UnixDate("today", "%z");
return $time;
}
</code>
The Benchmark results:
Benchmark: running DateManip, homeBrew for at least 10 CPU seconds...
DateManip: 11 wallclock secs (10.51 usr + 0.02 sys = 10.53 CPU) @
256.13/s (n=2697)
homeBrew: 11 wallclock secs ( 9.85 usr + 0.38 sys = 10.23 CPU) @
28406.06/s (n=290594)
Rate DateManip homeBrew
DateManip 256/s -- -99% homeBrew 28406/s 10991%
--
This shows that my algorithm is about 100x faster than using Date::Manip.
A significant difference I'd say.
Conclusion: if you have to format time in a high load environment, it's
definitely worth it to programm your own algorithms for formatting date
and time. If anyone has an even more efficient algorithm than mine, I'd
like to hear it.
-leendert bottelberghs
------------------------------
Date: Fri, 08 Apr 2005 07:31:07 -0400
From: Henry Townsend <henry.townsend@not.here>
Subject: Re: Windows fork emulation (and buffering?) problem
Message-Id: <ueidnav5RqPm9svfRVn-hg@comcast.com>
A. Sinan Unur wrote:
> Henry Townsend <henry.townsend@not.here> wrote in
> news:CJOdnXmZp9IJp8jfRVn-oA@comcast.com:
> Not an expert on how these things work, especially the whole dup thing,
> but I just checked,
>
> #! /usr/bin/perl
>
> use strict;
> use warnings;
>
> pipe my $reader, my $writer or die "Pipe failed: $!";
>
> my $pid = fork();
> if ($pid) {
> print "parent\n";
> close $writer;
> print "received: $_" while(<$reader>);
> print "done\n";
> wait;
> } elsif(defined $pid) {
> print "child\n";
> close $reader;
> local(*STDOUT) = $writer;
> print "data to writer\n";
> } else {
> die "Cannot fork: $!";
> }
> __END__
>
> seems to do what you want on Windows.
>
> That doesn't mean there is no bug, it might also be related to the
> warning against potential for deadlock in
>
> perldoc -f pipe
Yes, this works on Windows as well as Unix. Unfortunately I didn't go
into enough detail about what I'm trying to do. I need to capture stdout
and apply a regular expression to it, and when I say stdout I mean data
flowing from subprocesses as well as that originating from the perl
program. My fault for not making the distinction in the first place, but
the original code did an open() of STDOUT and thus operates on the file
*descriptor*, whereas your version operates on the file *handle*. The
difference being in what they do with (say)
system qw(cat file);
I'm moving on, playing with 4-arg select() and will report progress.
--
Henry Townsend
------------------------------
Date: Fri, 08 Apr 2005 12:20:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Windows fork emulation (and buffering?) problem
Message-Id: <Xns963254D758CA3asu1cornelledu@127.0.0.1>
Henry Townsend <henry.townsend@not.here> wrote in
news:ueidnav5RqPm9svfRVn-hg@comcast.com:
> A. Sinan Unur wrote:
>
>> Henry Townsend <henry.townsend@not.here> wrote in
>> news:CJOdnXmZp9IJp8jfRVn-oA@comcast.com:
>> Not an expert on how these things work, especially the whole dup
>> thing, but I just checked,
...
> *handle*. The difference being in what they do with (say)
>
> system qw(cat file);
I understand. Now, the question is, are you in control of the system
call above? If you are, and you need to process the output of an
external program, say cat, you could use backticks to launch it, or open
a pipe to it. The former would return all the output, the latter would
allow you to process the output of the external command line by line, as
in:
#! /usr/bin/perl
use strict;
use warnings;
open my $ls, 'ls -l |'
or die "Cannot pipe ls: $!";
while(<$ls>) {
next unless /\.pl$/;
print "Perl file: $_";
}
__END__
D:\Home\asu1\UseNet\clpmisc> myls
Perl file: -rwxr-xr-x 1 asu1 None 919 Jan 16 11:33 050116-a.pl
Perl file: -rwxr-xr-x 1 asu1 None 919 Jan 16 11:33 050116-b.pl
Perl file: -rwxr-xr-x 1 asu1 None 691 Jan 17 12:56 050117-b.pl
Perl file: -rwxr-xr-x 1 asu1 None 295 Jan 17 09:05 051117-a.pl
I am just not sure what you constraints are, so maybe I am suggesting
somehting that is not relevant to the particular problem you are trying
to solve.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
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 V10 Issue 7955
***************************************