[29535] in Perl-Users-Digest
Perl-Users Digest, Issue: 779 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 21 14:09:53 2007
Date: Tue, 21 Aug 2007 11:09:12 -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 Tue, 21 Aug 2007 Volume: 11 Number: 779
Today's topics:
Re: how to call sub by value in variable - SOLVED anno4000@radom.zrz.tu-berlin.de
Re: how to call sub by value in variable - SOLVED <nobull67@gmail.com>
Re: how to call sub by value in variable <nobull67@gmail.com>
how to connect to sybase in perl <honmancheung@gmail.com>
Re: how to connect to sybase in perl <larry.grant.dc@gmail.com>
Join lines nickli2000@gmail.com
Re: Join lines <mritty@gmail.com>
Re: Join lines <wahab@chemie.uni-halle.de>
Re: Mail::Sender problem <larry.grant.dc@gmail.com>
Re: Perl and JSP <glex_no-spam@qwest-spam-no.invalid>
Re: Perl performance difference between Linux distribut (Markus Kuhn)
Re: Perl sum of array and help with sorting <bik.mido@tiscalinet.it>
Re: Perldoc and the pipe "|" character <larry.grant.dc@gmail.com>
Re: Perldoc and the pipe "|" character <jkstill@gmail.com>
Re: Stumped: returning a read pipe from a function <socyl@987jk.com.invalid>
Re: Stumped: returning a read pipe from a function xhoster@gmail.com
Re: Stumped: returning a read pipe from a function <socyl@987jk.com.invalid>
Re: Stumped: returning a read pipe from a function <glex_no-spam@qwest-spam-no.invalid>
Submit Your Perl Scripts andrew.sain@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Aug 2007 08:13:31 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: how to call sub by value in variable - SOLVED
Message-Id: <5ivl5bF3rib9hU1@mid.dfncis.de>
Petr Vileta <stoupa@practisoft.cz> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson wrote:
> > Petr Vileta wrote:
> >> #!/usr/bin/perl
> >> use strict;
> >> use warnings;
> >>
> >> if(defined(&{"main::" . $sub}))
> >> {
> >> (\&$sub)->($name);
> >> }
> >
> > Too obfuscated to my taste. If you don't want to use a dispatch table,
> > why not just:
> >
> > no strict 'refs';
> > if ( defined &$sub ) {
> > $sub->($name);
> > }
> Yes, this may be used too, but I prefer to _not_ use no strict 'refs'. The
[...]
For completeness' sake, this also works under strict 'refs':
defined and $_->() for main->can( $sub);
Instead of "main" any package can be used, it could also be a variable
containing the package name. A problem is that "can()" does
inheritance, so if the package has a non-empty @ISA, a like-named sub
in another package could be found. The call itself is a plain sub
call, not a method call.
Anno
------------------------------
Date: Tue, 21 Aug 2007 10:22:56 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: how to call sub by value in variable - SOLVED
Message-Id: <1187716976.305907.74480@w3g2000hsg.googlegroups.com>
On Aug 20, 3:29 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
> if(defined(&{"main::" . $sub}))
> {
> (\&$sub)->($name);
> }
That makes no sense. You should either have the package name or not.
if(defined(&$sub))
{
(\&$sub)->($name);
}
OR
if(defined(&{"main::$sub"}))
{
(\&{"main::$sub"})->($name);
}
If the current package is main then the two are equivalent anyhow.
But using %main:: as you dispatch table is a really really bad idea.
And remember I'm the one who's saying that using a package as a
dispatch table is not _always_ a bad idea. (It is, after all, how Perl
implements OO).
You should have _some_ way in your code of distinguishing those
subroutines that are are intended via dynamic dispatch and those which
aren't.
If you don't like my preferred approach of using a separate package
then consider a prefix (or suffix for that matter) so that they still
have a defined namespace. (That's namespace in the general sense).
#!/usr/bin/perl
use strict;
use warnings;
# Create dispatch table of all functions with _handler suffix
my %handler = map { /(.*)_handler$/ ? ( $1 => \&$_ ) : () } keys %::;
foreach my $action (qw/test1 test3 test2/) {
foreach my $name (qw/Petr John/) {
if( $handler{$action}) {
$handler{$action}->($name);
} else {
warn "Handler for '$action' not defined\n";
last;
}
}
}
sub test1_handler {
my $txt=shift;
print "Hallo $txt\n";
}
sub test2_handler {
my $txt=shift;
print "Bye $txt\n";
}
__END__
And before anyone else points it out, I do realise this would get
confused if you had, for example, a variable $main::test3_handler.
As Uri correctly points out you could replace the run-time examination
of %:: with a code preprocessor.
------------------------------
Date: Tue, 21 Aug 2007 09:45:57 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: how to call sub by value in variable
Message-Id: <1187714757.652826.246350@a39g2000hsc.googlegroups.com>
On Aug 20, 3:09 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
> Brian McCauley wrote:
> > It's trivial to use CODE symrefs without switching off use strict.
>
> > (\&$sub)->($name);
>
> Yippee :-) This is what I looked for.
No! Please no! The above code is using symrefs but not _obviously_
using symrefs. If you are using symrefs your code should look like it
is. The easiest way to do this to put it in a a "no strict 'refs'"
block.
------------------------------
Date: Tue, 21 Aug 2007 06:02:21 -0700
From: German <honmancheung@gmail.com>
Subject: how to connect to sybase in perl
Message-Id: <1187701341.352118.321230@22g2000hsm.googlegroups.com>
I am having trouble to connect to Sybase using perl. I am currently
running windows on my machine. I got the following errors when I ran
the script.
install_driver(Sybase) failed: Can't locate DBD/Sybase.pm in @INC
(@INC contains
: c:/Program Files/Perl/lib c:/Program Files/Perl/site/lib .) at (eval
1) line 3
.
Perhaps the DBD::Sybase perl module hasn't been fully installed,
or perhaps the capitalisation of 'Sybase' isn't right.
Available drivers: CSV, DB2, DBM, ExampleP, File, ODBC, Proxy, Sponge.
It seems to me that I need to install the module, but I can't find the
module for windows online. Any ideas?
Thanks in advance
------------------------------
Date: Tue, 21 Aug 2007 17:32:51 -0000
From: Larry <larry.grant.dc@gmail.com>
Subject: Re: how to connect to sybase in perl
Message-Id: <1187717571.176421.115100@k79g2000hse.googlegroups.com>
On Aug 21, 9:02 am, German <honmanche...@gmail.com> wrote:
> I am having trouble to connect to Sybase using perl. I am currently
> running windows on my machine. I got the following errors when I ran
> the script.
>
> install_driver(Sybase) failed: Can't locate DBD/Sybase.pm in @INC
> (@INC contains
> : c:/Program Files/Perl/lib c:/Program Files/Perl/site/lib .) at (eval
> 1) line 3
> .
> Perhaps the DBD::Sybase perl module hasn't been fully installed,
> or perhaps the capitalisation of 'Sybase' isn't right.
> Available drivers: CSV, DB2, DBM, ExampleP, File, ODBC, Proxy, Sponge.
>
> It seems to me that I need to install the module, but I can't find the
> module for windows online. Any ideas?
>
> Thanks in advance
Are you using ActiveState Perl? If so, they have some Sybase modules
available through Perl Package Manager.
------------------------------
Date: Tue, 21 Aug 2007 09:45:05 -0700
From: nickli2000@gmail.com
Subject: Join lines
Message-Id: <1187714705.322892.243340@a39g2000hsc.googlegroups.com>
Hi,
I have a file with a lot of lines with a singer number like the
following:
111
222
333
444
555
6666
77777
888
9999
..........
How could I join 3 lines at a time and with a "," in between and at
the beginning of the next line, as in the following:
111,222,333
,444,555,6666
,77777,888,9999
.........
Thanks in advance.
Nick Li
------------------------------
Date: Tue, 21 Aug 2007 09:57:02 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Join lines
Message-Id: <1187715422.158973.93690@50g2000hsm.googlegroups.com>
On Aug 21, 12:45 pm, nickli2...@gmail.com wrote:
> I have a file with a lot of lines with a singer number like the
> following:
>
> 111
> 222
> 333
> 444
> 555
> 6666
> 77777
> 888
> 9999
> ..........
>
> How could I join 3 lines at a time and with a "," in between and at
> the beginning of the next line, as in the following:
>
> 111,222,333
> ,444,555,6666
> ,77777,888,9999
> .........
$ cat clpm.pl
#!/opt2/perl/bin/perl
use strict;
use warnings;
while (my $line = <DATA>) {
chomp $line;
print $line;
print "\n" if $. % 3 == 0;
print ",";
}
print "\n";
__DATA__
111
222
333
444
555
6666
77777
888
9999
$ ./clpm.pl
111,222,333
,444,555,6666
,77777,888,9999
,
$
Paul Lalli
------------------------------
Date: Tue, 21 Aug 2007 19:16:15 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Join lines
Message-Id: <faf6i6$1o0i$1@nserver.hrz.tu-freiberg.de>
nickli2000@gmail.com wrote:
> I have a file with a lot of lines with a singer number like the
> following:
> 111
> 222
> 333
> 444
> 555
> 6666
> 77777
> 888
> 9999
> ..........
>
> How could I join 3 lines at a time and with a "," in between and at
> the beginning of the next line, as in the following:
> 111,222,333
> ,444,555,6666
> ,77777,888,9999
Is this Unix/Linux? Then do a simple:
perl -0777 -pe 's/\n/(++$n%3)?",":"\n,"/eg' lines.txt > commas.txt
if your file is 'lines.txt'.
In Win32, you have to change the quotes.
Regards
M.
------------------------------
Date: Tue, 21 Aug 2007 17:38:48 -0000
From: Larry <larry.grant.dc@gmail.com>
Subject: Re: Mail::Sender problem
Message-Id: <1187717928.606464.265580@o80g2000hse.googlegroups.com>
On Aug 20, 7:58 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> jis wrote:
> > I wrote a program to send email. It looks as below
>
> > use strict;
> > use Mail::Sender;
>
> <snip>
>
> > This works fine for me without any issues.
> > I converted this script to exe using p2x-8.80-Win32.It gave warnings
> > initially with
> > 1. Config file missing.
> > 2. Langinfo.pm missing.
> > 3. Digest::Perl::MD5 missing
>
> > I re installed Mail::Sender to make sure that there is a config file.
>
> Did that really make a difference with respect to the config file
> Perl2Exe complained about?
>
> > I manually copied LangInfo.pm to the I18N folder under C:\\perl\\lib.
> > ALso installed MD5 from cpan.
>
> > I converted to exe without any warnings.
> > But when I run exe it throws the error
> > " -3Error Sending
> > mail: Connect failed:An established connection was aborted by
> > software
> > in your host machine" . I do not have problems when I go back and run
> > my perl file.
>
> > I use Windows xp, Active perl 5.8.8 Build 820, Mail::sender 0.8.13
> > I use p2x-8.80-Win32 to convert .pl to .exe.I did not have any
> > problems while converting to exe before.Ofcourse I never used
> > Mail::Sender before.
>
> I know that Mail::Sender was written with conversion to .exe files in
> mind, so it ought to be a good choice for the purpose.
>
> Maybe you should try to get in touch with the Mail::Sender author.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Why are you messing with CPAN and copying things manually? If you
have ActiveState Perl you should use Perl Package Manager to install
your packages.
------------------------------
Date: Tue, 21 Aug 2007 11:52:07 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl and JSP
Message-Id: <46cb1838$0$495$815e3792@news.qwest.net>
Saran.j.jegan@gmail.com wrote:
> On Aug 21, 10:27 am, Saran.j.je...@gmail.com wrote:
>>> Saran.j.je...@gmail.com wrote:
>>>> Hello,
>>>> we have developed an web based application for monitoring
>>>> and controlling some machines using Java & JSP in apache tomcat, now
>>>> we have planned to replace some java programs such as serial port
>>>> communications and socket level communication with CGI scripts using
>>>> perl & c , Hope it will be faster than old java codes,
[...]
> i think it will be a good experimental one ,certainly its going to be
> implemented on a industrial PC which will be more compact one with XP
> embedded and linux , so removing java fundas will give some space and
> perl's flexibility will help a lot, as you said it also depends on the
> programmers hands with the language
The word boondoggle comes to mind.
You have something that works on a reliable platform and now you
want to change everything to see if it will run a little faster? It
seems like a complete waste of time and money, to me. IMHO,
your effort would be better spent in figuring out ways to speed
up your current system.
Don't get me wrong, I use perl for everything, but when your
company's expertise is in Java/JSP, switching to another
language and system could be a disaster and put you further
behind in figuring out the actual problem.
------------------------------
Date: 21 Aug 2007 15:09:30 GMT
From: n07W34+mgk25@cl.cam.ac.uk (Markus Kuhn)
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <faev7a$362$1@gemini.csx.cam.ac.uk>
I have now filed a bug report on this issue at
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=253728
Markus
--
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain
------------------------------
Date: Tue, 21 Aug 2007 10:39:26 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl sum of array and help with sorting
Message-Id: <ol8lc3p0pb11o88ofdskrgbvgb5vo0mplv@4ax.com>
On Mon, 20 Aug 2007 19:44:12 -0000, elroyerni <davechunny@gmail.com>
wrote:
>sub sum_array {
> my($sum) = 0; # initialize the sum to 0
> foreach $i (@array_data) {
> $sum = $sum + $i;
> }
> return($sum);
>}
In addition to all that's been told to you, it's also worth to notice
that you're writing a separate sub to sum a *specific* array. This is
*legitimate*, but most probably *not* the best thing to do. Taking
your sub as it is, just modify it like
sub sum_array {
my($sum) = 0; # initialize the sum to 0
foreach $i (@_) {
$sum = $sum + $i;
}
return($sum);
}
so that you can call it like thus:
my $sum1 = sum_array(@array1);
my $sum2 = sum_array(@array2);
# and so on...
Of course when you've modified it this way you can sum not only
arrays, but arbitrary lists:
my $sum = sum_array(1,2.5,3);
At this point the name is misleading at best, and I would probably go
for just 'sum'. BTW: a completely equivalent but more perlish way in
which probably most Perl programmers would write it is
sub sum {
my $sum;
$sum += $_ for @_;
$sum;
}
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 21 Aug 2007 17:41:10 -0000
From: Larry <larry.grant.dc@gmail.com>
Subject: Re: Perldoc and the pipe "|" character
Message-Id: <1187718070.857092.289020@22g2000hsm.googlegroups.com>
On Aug 20, 4:59 pm, jkstill <jkst...@gmail.com> wrote:
> While cutting and pasting an example from a script viewed via perldoc,
> the example would not work.
>
> The problem was that perldoc was displaying the pipe chr(124) and a
> similar character, chr(226).
>
> I have reviewed the docs on perldoc, but have been unable to get any
> method to work so that the pipe symbol is properly displayed.
>
> This is on RH Linux ES 4, 2.6 kernel.
>
> Perl is 5.8.8
>
> Here is a snippet from the displayed documentation:
>
> ps -e -o user --no-headers =E2=94=82 sort -u=E2=94=82
>
> As you can see those are not pipes - |
>
> What might be the reason for this, and a solution to get the | to
> display properly?
How do you know the author didn't put the bad character in there
himself (by mistake)? If so, Perldoc is simply giving you what the
author put in (GIGO).
------------------------------
Date: Tue, 21 Aug 2007 18:06:29 -0000
From: jkstill <jkstill@gmail.com>
Subject: Re: Perldoc and the pipe "|" character
Message-Id: <1187719589.913490.206620@x35g2000prf.googlegroups.com>
On Aug 21, 10:41 am, Larry <larry.grant...@gmail.com> wrote:
> On Aug 20, 4:59 pm, jkstill <jkst...@gmail.com> wrote:
>
>
>
> > While cutting and pasting an example from a script viewed via perldoc,
> > the example would not work.
>
> > The problem was that perldoc was displaying the pipe chr(124) and a
> > similar character, chr(226).
>
> > I have reviewed the docs on perldoc, but have been unable to get any
> > method to work so that the pipe symbol is properly displayed.
>
> > This is on RH Linux ES 4, 2.6 kernel.
>
> > Perl is 5.8.8
>
> > Here is a snippet from the displayed documentation:
>
> > ps -e -o user --no-headers =E2=94=82 sort -u=E2=94=82
>
> > As you can see those are not pipes - |
>
> > What might be the reason for this, and a solution to get the | to
> > display properly?
>
> How do you know the author didn't put the bad character in there
> himself (by mistake)? If so, Perldoc is simply giving you what the
> author put in (GIGO).
Because I am the author, and the command was cut and pasted from the
command line into the pod section of the script.
The character in the script is correct.
Try this. Create a file called pod_pipe.pl with nothing in it but a
pod section:
jkstill-6 > cat pod_pipe.pl
=3Dhead1 Does the pipe display correctly?
this is a pipe: |
=3Dcut
Now here is the output from perldoc:
POD_PIPE(1) User Contributed Perl Documentation
POD_PIPE(1)
Does the pipe display correctly?
this is a pipe: =E2=94=82
perl v5.8.8 2007-08-21
POD_PIPE(1)
Notice that the symbol displayed by cat and the symbol displayed by
perldoc are different.
------------------------------
Date: Tue, 21 Aug 2007 15:03:10 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: Stumped: returning a read pipe from a function
Message-Id: <faeurd$rmp$1@reader1.panix.com>
In <20070820234228.459$Zn@newsreader.com> xhoster@gmail.com writes:
>kj <socyl@987jk.com.invalid> wrote:
>>
>> use IPC::Open3 'open3';
>> use IO::Unread 'unread';
>Boy are you ever piling on the complications here.
The complication is not entirely obvious to me, but at any rate
well, I'm open to suggestions... Your idea of saving the entire
output of the command to a file is unpalatable because this output
*can* be huge and the function downstream may need only the first
few hundred lines of this huge output. It just so happens that,
by far, the most common possible outcomes for '/some/command' are
either success with a many lines of output or immediate failure
with a one-line error message. Hence, the idea of checking for
eof after the first line happens to work in this special case.
But the downstream function requires a filehandle (as opposed to
a pair of handle and string), hence the business with unread.
>From the docs:
<the rest snipped to ease my pain>
To say that there's egg on my face would be an understatement...
I had in fact read that in the docs not too long ago, and (since
it did not make much sense at the time) I immediately forgot it.
Thanks for the reminder.
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: 21 Aug 2007 16:17:15 GMT
From: xhoster@gmail.com
Subject: Re: Stumped: returning a read pipe from a function
Message-Id: <20070821121717.488$RO@newsreader.com>
kj <socyl@987jk.com.invalid> wrote:
> In <20070820234228.459$Zn@newsreader.com> xhoster@gmail.com writes:
>
> >kj <socyl@987jk.com.invalid> wrote:
> >>
> >> use IPC::Open3 'open3';
> >> use IO::Unread 'unread';
>
> >Boy are you ever piling on the complications here.
>
> The complication is not entirely obvious to me,
As long as only one part of the code is being clever, you are OK.
But when many parts of the code are being clever, they start tripping
over each other. IO::Unread hiddenly ties and unties file handles (at
least in some situations), so if the whatever you returning the handle to
also, either now or in the future, wants to tie it or get the fd and pass
that out to some other program, it will fail. That is the complexity. I
usually consider things like IO::Unread and Tie::File to be emergency
life-support methods. If I need them, it probably means the code isn't
well-designed for the task that it is currently being used for, and I use
those modules to keep the old code limping along while I'm busy redesigning
and rewriting.
> but at any rate
> well, I'm open to suggestions...
Based on your last code, if I understand what you are doing and if you
fix the $err thing and make the changes that go with that, you don't need
to read the line from $rdr at all.
Just call eof($rdr) right off the bat. If it returns true, that means
the program exited (or at least closed its own stdout) without producing
any output on stdout. So then you read $err (or *ERR), plus you can wait
on $pid and see what $? is. Based on that, you decide if it was a
error-free empty output, or a error-caused empty output, and either die, or
return the (already at eof, but who cares) $rdr. If eof($rdr) returns
false, it means that at least something was printed to stdout, so in your
model that would mean there is no error, so return the file handle. This
could deadlock if the error message is more than one buffer in size, but as
you say it is can only ever be exactly zero or one lines, that seems
unlikely.
Another issue is that, if this subroutine is invoked many times during
the lifetime of the program, you need a way to wait on the child or
you will accumulate zombies.
> Your idea of saving the entire
> output of the command to a file is unpalatable because this output
> *can* be huge and the function downstream may need only the first
> few hundred lines of this huge output. It just so happens that,
> by far, the most common possible outcomes for '/some/command' are
> either success with a many lines of output or immediate failure
> with a one-line error message.
Even if the alternatives besides those two are very rare, do they still
need to be dealt with? I've often painted myself into a corner by using
a method that made it easy to deal with 99.99% but then made it nearly
impossible to deal with the other 0.01%. So now I'm very leery about
things that look like they are starting down that road.
> Hence, the idea of checking for
> eof after the first line happens to work in this special case.
In your most recent code as it is (i.e. not corrected for the $err thing),
you will report an error if there the program has no error and produces
exactly one line of output. Since you previously said that it is legal
to produce exactly zero lines of output on non-error conditions, I suspect
it is also legal to produce exactly one. So you may falsely be reporting
errors.
> But the downstream function requires a filehandle (as opposed to
> a pair of handle and string), hence the business with unread.
As I said, I am somewhat skeptical if this approach is to be used as a base
for future growth and evolution. However, if you (correctly) suspect that
your code will not keep evolving in new directions once you have this
particular issue worked out, then I guess this is of lesser concern.
>
> >From the docs:
>
> <the rest snipped to ease my pain>
>
> To say that there's egg on my face would be an understatement...
> I had in fact read that in the docs not too long ago, and (since
> it did not make much sense at the time) I immediately forgot it.
> Thanks for the reminder.
The IPC::Open3 behavior is so incredibly counter-intuitive that that
part of the docs just don't sink in the first few times you get bit by it.
It doesn't help that the docs themselves provide absurd examples:
my($wtr, $rdr, $err);
$pid = open3($wtr, $rdr, $err,
'some cmd and args', 'optarg', ...);
Why the heck go to the effort of declaring $err and passing it in,
if the net effect is identical to:
my($wtr, $rdr);
$pid = open3($wtr, $rdr, undef,
'some cmd and args', 'optarg', ...);
That is highly misleading.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 21 Aug 2007 17:24:37 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: Stumped: returning a read pipe from a function
Message-Id: <faf74l$71c$1@reader1.panix.com>
In <20070821121717.488$RO@newsreader.com> xhoster@gmail.com writes:
>Just call eof($rdr) right off the bat.
That works great, reducing the function to:
use IPC::Open3 'open3';
use Symbol 'gensym';
sub foo {
my $err = gensym;
my $pid = open3( my ( $wtr, $rdr ), $err,
'/some/command', @_ );
close $wtr;
die join '', <$err> if eof $rdr;
return $rdr;
}
Thanks.
I'm still mulling over the zombies issue...
Maybe...
use IPC::Open3 'open3';
use Symbol 'gensym';
use IO::Handle;
sub foo {
my $rdr = Ugly::Kluge->new;
my $err = gensym;
my $pid = open3( my $wtr, $rdr, $err,
'/some/command', @_ );
${ *$rdr{ SCALAR } } = $pid; # Yeeeew!
close $wtr;
die join '', <$err> if eof $rdr;
return $rdr;
}
{
package Ugly::Kluge;
use POSIX 'SIGTERM';
our @ISA = 'IO::Handle';
sub DESTROY {
my $self = shift;
if ( defined( my $pid = ${ *$self{ SCALAR } } ) ) {
kill SIGTERM, $pid;
waitpid( $pid, 0 );
}
$self->SUPER::DESTROY;
}
}
OK, time to open the windows here, and air out the place...
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Tue, 21 Aug 2007 12:33:49 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Stumped: returning a read pipe from a function
Message-Id: <46cb21fd$0$513$815e3792@news.qwest.net>
kj wrote:
> In <20070821121717.488$RO@newsreader.com> xhoster@gmail.com writes:
>
>> Just call eof($rdr) right off the bat.
>
> That works great, reducing the function to:
>
> use IPC::Open3 'open3';
> use Symbol 'gensym';
>
> sub foo {
> my $err = gensym;
> my $pid = open3( my ( $wtr, $rdr ), $err,
> '/some/command', @_ );
> close $wtr;
> die join '', <$err> if eof $rdr;
>
Why call join?
die <$err> if eof $rdr;
------------------------------
Date: Tue, 21 Aug 2007 10:45:40 -0700
From: andrew.sain@gmail.com
Subject: Submit Your Perl Scripts
Message-Id: <1187718340.500985.254820@50g2000hsm.googlegroups.com>
Hi, just wanted to invite any Perl script authors to submit their Perl
script to our popular software site
at http://www.myzips.com
We have just today added a "Scripts" directory which includes a Perl
subdirectory
http://www.myzips.com/category/Scripts/
The first submissions usually maintain a high position in our
directories so the sooner you can get your
script listed the more exposure you should be able to receive for your
script.
You can also submit PHP, AJAX, ASP, Ruby on Rails, CGI, Flash, Python,
CFML, .NET, Java, XML and C/C++ scripts and coding.
Thanks for your time,
Andy
------------------------------
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 779
**************************************