[25115] in Perl-Users-Digest
Perl-Users Digest, Issue: 7365 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 5 14:10:35 2004
Date: Fri, 5 Nov 2004 11:10:11 -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 Fri, 5 Nov 2004 Volume: 10 Number: 7365
Today's topics:
How to open a pipe for reading and writing? <winston_smith@linuxmail.org>
Re: How to open a pipe for reading and writing? <richard@zync.co.uk>
Re: How to open a pipe for reading and writing? <nobull@mail.com>
Re: How to open a pipe for reading and writing? <dwall@fastmail.fm>
Re: How to open a pipe for reading and writing? <dwall@fastmail.fm>
Re: How to open a pipe for reading and writing? <jgibson@mail.arc.nasa.gov>
Re: How to open a pipe for reading and writing? <stampes@xilinx.com>
lists,shift,subs and dumb question <jeff@spamalanadingong.com>
Re: lists,shift,subs and dumb question <noreply@gunnar.cc>
Re: lists,shift,subs and dumb question <jeff@spamalanadingong.com>
Re: lists,shift,subs and dumb question <uguttman@athenahealth.com>
Re: lists,shift,subs and dumb question <noreply@gunnar.cc>
Re: lists,shift,subs and dumb question <uguttman@athenahealth.com>
passing colon or comma as part of arg list to exec (Bill Babcock)
Re: passing colon or comma as part of arg list to exec <nobull@mail.com>
Re: passing colon or comma as part of arg list to exec <Joe.Smith@inwap.com>
Re: Q: re Inline and Benchmark <kalinaubears@iinet.net.au>
Re: Spurious "Use of uninitialized value" with -w, redu <tadmc@augustmail.com>
Win32::OLE msxml collection problem <lumbus@ludd.luth.se>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Nov 2004 16:16:21 GMT
From: Winston Smith <winston_smith@linuxmail.org>
Subject: How to open a pipe for reading and writing?
Message-Id: <pHNid.156349$0f.64649@charlie.risq.qc.ca>
Hello,
I would like to know if there is a way to open a pipie for both reading
and writing ? What I'm trying to do is something like:
open(FILTRE, '| myprogram |');
while (<>) {
print FILTRE, $_;
my $result = <FILTRE>;
print STDOUT, $result;
}
The point is I need to give lines one by one to my program and read the
output in the same time (as the output for a given line can change the
following input).
If someone as any idea, thank you in advance.
Winston
------------------------------
Date: Fri, 05 Nov 2004 17:20:44 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Re: How to open a pipe for reading and writing?
Message-Id: <pan.2004.11.05.17.20.44.546709@zync.co.uk>
On Fri, 05 Nov 2004 16:16:21 +0000, Winston Smith wrote:
> Hello,
>
> I would like to know if there is a way to open a pipe for both reading
> and writing ?
<SNIP>
> If someone as any idea, thank you in advance.
Use IPC::Open2.
It's quite straightforward, there's good example code in the docs for it.
HTH
Rich
------------------------------
Date: Fri, 05 Nov 2004 17:19:22 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to open a pipe for reading and writing?
Message-Id: <cmgcdv$5ns$2@sun3.bham.ac.uk>
Winston Smith wrote:
[ FAQ: "How can I open a pipe both to and from a command?" ]
> thank you in advance.
If you are going to do anything in advance, it should be to read the FAQ.
------------------------------
Date: Fri, 05 Nov 2004 17:27:10 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: How to open a pipe for reading and writing?
Message-Id: <Xns95987EAD613B3dkwwashere@216.168.3.30>
Winston Smith <winston_smith@linuxmail.org> wrote:
> I would like to know if there is a way to open a pipie for both
> reading and writing ? What I'm trying to do is something like:
>
> open(FILTRE, '| myprogram |');
I'd read the docs for open() and see where else that led me.
------------------------------
Date: Fri, 05 Nov 2004 17:29:49 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: How to open a pipe for reading and writing?
Message-Id: <Xns95987F20495CCdkwwashere@216.168.3.30>
Brian McCauley <nobull@mail.com> wrote:
> Winston Smith wrote:
>
> [ FAQ: "How can I open a pipe both to and from a command?" ]
>
>> thank you in advance.
>
> If you are going to do anything in advance, it should be to read
> the FAQ.
I think I need to reread the FAQ myself: a routine brain maintenance
task I've deferred for too long.
------------------------------
Date: Fri, 05 Nov 2004 09:43:29 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to open a pipe for reading and writing?
Message-Id: <051120040943298153%jgibson@mail.arc.nasa.gov>
In article <pHNid.156349$0f.64649@charlie.risq.qc.ca>, Winston Smith
<winston_smith@linuxmail.org> wrote:
> Hello,
>
> I would like to know if there is a way to open a pipie for both reading
> and writing ? What I'm trying to do is something like:
>
> open(FILTRE, '| myprogram |');
> while (<>) {
> print FILTRE, $_;
> my $result = <FILTRE>;
> print STDOUT, $result;
> }
>
> The point is I need to give lines one by one to my program and read the
> output in the same time (as the output for a given line can change the
> following input).
>
> If someone as any idea, thank you in advance.
>
> Winston
>
See 'perldoc -f open' and look for the paragraph starting with "If the
filename begins with '|'", which tells you that you can't do that, but
recommends you "See 'Using open() for IPC' in perlipc" and "see
IPC::Open2, IPC::Open3, and 'Bidirectional Communication' in perlipc".
------------------------------
Date: Fri, 05 Nov 2004 10:26:29 -0700
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: How to open a pipe for reading and writing?
Message-Id: <cmgdce$esg1@xco-news.xilinx.com>
Winston Smith wrote:
> I would like to know if there is a way to open a pipie for both reading
> and writing ?
Found in /usr/lib/perl5/5.8.3/pod/perlfaq8.pod
How can I open a pipe both to and from a command?
The IPC::Open2 module (part of the standard perl distribution) is a easy-to-
use approach that internally uses pipe(), fork(), and exec() to do the job.
Make sure you read the deadlock warnings in its documentation, though (see
IPC::Open2). See "Bidirectional Communication with Another Process" in per-
lipc and "Bidirectional Communication with Yourself" in perlipc
You may also use the IPC::Open3 module (part of the standard perl distribu-
tion), but be warned that it has a different order of arguments from
IPC::Open2 (see IPC::Open3).
------------------------------
Date: Fri, 05 Nov 2004 16:23:17 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: lists,shift,subs and dumb question
Message-Id: <VNNid.881$_J2.483@newsread2.news.atl.earthlink.net>
I'm calling a sub with an empty value in the list
Method A:
someSub('val1',,'val3');
Method B:
someSub('val1','','val3');
sub someSub{
my $val1=shift;
my $val2=shift;
my $val3=shift;
}
with method A, $val2 is val3
why is it not undef?
Cheers,
Jeff
------------------------------
Date: Fri, 05 Nov 2004 17:32:48 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: lists,shift,subs and dumb question
Message-Id: <2v1oh2F2g8qiuU1@uni-berlin.de>
Jeff Thies wrote:
> I'm calling a sub with an empty value in the list
>
> Method A:
> someSub('val1',,'val3');
>
> Method B:
> someSub('val1','','val3');
>
> sub someSub{
> my $val1=shift;
> my $val2=shift;
> my $val3=shift;
> }
>
> with method A, $val2 is val3
>
> why is it not undef?
Because you didn't pass any undef element. You can do:
someSub('val1', undef, 'val3');
See "perldoc perldata" about the impact of multiple commas.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 05 Nov 2004 17:16:35 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: Re: lists,shift,subs and dumb question
Message-Id: <TzOid.925$_J2.461@newsread2.news.atl.earthlink.net>
Gunnar Hjalmarsson wrote:
> Jeff Thies wrote:
>
>> I'm calling a sub with an empty value in the list
>>
>> Method A:
>> someSub('val1',,'val3');
>>
>> Method B:
>> someSub('val1','','val3');
>>
>> sub someSub{
>> my $val1=shift;
>> my $val2=shift;
>> my $val3=shift;
>> }
>>
>> with method A, $val2 is val3
>>
>> why is it not undef?
>
>
> Because you didn't pass any undef element. You can do:
>
> someSub('val1', undef, 'val3');
>
> See "perldoc perldata" about the impact of multiple commas.
Thanks, Looks like I made a List of lists without realizing it.
(('val1',),('val3'))
I can see why perlsub said nothing abouty this.
Cheers,
Jeff
>
------------------------------
Date: Fri, 05 Nov 2004 13:17:47 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: lists,shift,subs and dumb question
Message-Id: <m3oeickvn8.fsf@lap.athenahealth.com>
>>>>> "JT" == Jeff Thies <jeff@spamalanadingong.com> writes:
JT> Thanks, Looks like I made a List of lists without realizing it.
JT> (('val1',),('val3'))
huh? that isn't a list of lists. parens just group and manage
precedence. LoL needs array refs and you have none there. the rule you
aren't getting has nothing to do with subs but with list context (that
calling a sub provides to its params). the same would be true if you
just assigned your params to an array. empty elements (not undef but
nothing between commas) are ignored in list context. they are not ever
passed since there is nothing to pass.
JT> I can see why perlsub said nothing abouty this.
it doesn't because it is a list context issue and not a sub issue.
uri
------------------------------
Date: Fri, 05 Nov 2004 19:33:05 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: lists,shift,subs and dumb question
Message-Id: <2v1vj1F2hmrheU1@uni-berlin.de>
Uri Guttman wrote:
> Jeff Thies writes:
>> Thanks, Looks like I made a List of lists without realizing it.
>> (('val1',),('val3'))
>
> huh? that isn't a list of lists.
Quote from "perldoc perldata":
"The list 1,,3 is a concatenation of two lists, ..."
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 05 Nov 2004 13:39:04 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: lists,shift,subs and dumb question
Message-Id: <m3k6t0kunr.fsf@lap.athenahealth.com>
>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
GH> Uri Guttman wrote:
>> Jeff Thies writes:
>>> Thanks, Looks like I made a List of lists without realizing it.
>>> (('val1',),('val3'))
>> huh? that isn't a list of lists.
GH> Quote from "perldoc perldata":
GH> "The list 1,,3 is a concatenation of two lists, ..."
that still isn't a list of lists. it creates a single list without the
missing element. that is what matters. there is no 'list concatenate'
operator so that is compiled into a single list. semanitic nits maybe :)
uri
------------------------------
Date: 5 Nov 2004 09:16:48 -0800
From: billbabcockIII@yahoo.com (Bill Babcock)
Subject: passing colon or comma as part of arg list to exec
Message-Id: <6723460c.0411050916.3a164033@posting.google.com>
tcpreplay has a facility to remap IP address in a capfile.
The format for that arg is so:
-N 192.168.0.1/32:1.0.0.1/32,192.168.0.100/32:2.0.0.1/32
When I try to pass that via exec:
my @args =
("$tcpreplay", "-p", "$pps",
"-i", "$eth",
"-N", "$src_ip/32:$src,$dest_ip/32:$dst",
"$capfile,
"2>&1");
exec (@args) or die "cannot exec tcpreplay: $!\n";
It ends up that the colon and comma are treated, I believe, as shell
escapes, and so are turned into whitespace separating the arg for the
-N flag. A ps shows this:
/usr/sbin/tcpreplay -p 1 -i eth2 -N 192.168.0.6/32 1.0.0.1/32
192.168.0.2/32 2.0.0.1/32 data.cap 2>&1
I am unable to get around the issue of the colon and comma being
rendered to spaces.
I get the same result wether using backticks, system or exec. I've
tried using the indirect object approach
exec { $args[0] } @args;
- same result.
Any suggestions very much appreciated.
- bill
------------------------------
Date: Fri, 05 Nov 2004 17:36:09 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: passing colon or comma as part of arg list to exec
Message-Id: <cmgddf$6bi$1@sun3.bham.ac.uk>
Bill Babcock wrote:
> tcpreplay has a facility to remap IP address in a capfile.
> The format for that arg is so:
> -N 192.168.0.1/32:1.0.0.1/32,192.168.0.100/32:2.0.0.1/32
>
> When I try to pass that via exec:
> my @args =
> ("$tcpreplay", "-p", "$pps",
> "-i", "$eth",
> "-N", "$src_ip/32:$src,$dest_ip/32:$dst",
> "$capfile,
> "2>&1");
>
> exec (@args) or die "cannot exec tcpreplay: $!\n";
>
That code will not compile. What does your code actually look like?
> It ends up that the colon and comma are treated, I believe, as shell
> escapes, and so are turned into whitespace separating the arg for the
> -N flag.
This should not be the case. Using the LIST form of exec there is no
shell involvement thus : and , should not be treated as shell
metacharacters. Nor for that matter would the "2>&1" be treated as a
shell redirection.
> A ps shows this:
>
> /usr/sbin/tcpreplay -p 1 -i eth2 -N 192.168.0.6/32 1.0.0.1/32
> 192.168.0.2/32 2.0.0.1/32 data.cap 2>&1
>
> I am unable to get around the issue of the colon and comma being
> rendered to spaces.
Any if you issue the command from the command line by hand, does the
same happen? It is possible the program tcpreplay is altering its
paramters.
------------------------------
Date: Fri, 05 Nov 2004 18:58:22 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: passing colon or comma as part of arg list to exec
Message-Id: <h3Qid.368657$D%.142565@attbi_s51>
Bill Babcock wrote:
> When I try to pass that via exec:
> my @args =
> ("$tcpreplay", "-p", "$pps",
> "-i", "$eth",
> "-N", "$src_ip/32:$src,$dest_ip/32:$dst",
> "$capfile,
> "2>&1");
>
> exec (@args) or die "cannot exec tcpreplay: $!\n";
Whenever you're planing to use "2>&1" or other /bin/sh syntax,
you need to pass a single string, not a list of strings.
What happens when you do it as one string?
$cmd = "$tcpreplay -p $pps -i $eth -N $src_ip/32:$src,$dest_ip/32:$dst
$capfile 2>&1";
print "About to execute '$cmd'\n"; # Verify argument string
system "echo $cmd"; # Verify what /bin/sh sees
exec $cmd;
-Joe
------------------------------
Date: Fri, 05 Nov 2004 18:46:01 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <418bcbbe$0$6547$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Michele Dondi wrote:
>
>>suspect you're also getting the trailing NULL character in strings that
>>it returns. However, on Linux, that 21st character often shows up as a
>>'1'. I can't explain that. On a couple of occasions it returned a string
>
>
> Huh?!
Let's just say that when you 'return(str)' you return up until the first
NULL is reached. In this case the 21st character is a '1' and the 22nd
character is a NULL. When I started running this on Win32 I sometimes
got 25 characters back before a NULL was reached.
>
>
>>that was less than 20 characters long - perhaps because of an embedded
>>NULL character in the string, so it probably pays to check that you get
>>the full quota returned.
>
There's no "perhaps" about it - it's definitely what was happening. And
the longer the string, the greater the chance that you'll strike a NULL
before you get that full quota back.
>
> Ditto as above! Many good points IMHO make all this stuff an
> interesting case study...
>
'abigail()' is buggy, non-portable (Win32 doesn't like
'perror(malloc)'), and leaks - though the bugs and portability issue are
easily fixed. (See revised code below.)
'sisyphus2()' despite addressing the "buffer duplication" issue, is
about 4 times slower than 'sisyphus()'. This is because 'sv_insert()' is
slow. Maybe there's a more efficient way of setting the characters of
a SV to random values. If there is, then I couldn't find it, and we'll
have to wait for someone else to tell us about it.
The only changes I've made to 'sisyphus()' and 'sisyphus2()' is to take
values mod 256 (not 255). This means that those 2 subs produce
characters in the range chr(0)..chr(255), whereas 'abigail()' produces
characters in the range chr(1)..chr(255). You can suit yourself in
regard to this - the important thing is that you don't want to let
'abigail()' produce NULL characters.
I've also restored 'l' to the original value of 20000.
Just use the 'sisyphus()' subroutine - which is essentially as I posted
in the first place - unless someone can convince you to do otherwise.
use warnings;
use Benchmark;
use Inline C => Config =>
BUILD_NOISY => 1;
use Inline C => <<'EOC';
char * abigail () {
char * str;
int i;
int l;
l = 20000;
srand (time ((time_t) NULL));
if ((str = (char *) malloc ((l + 1) * sizeof (char))) ==
(char *) NULL) {
croak("Failed to allocate memory in abigail()");
}
for (i = 0; i < l; i ++) {
str [i] = (rand () % 255) + 1;
}
str[l] = 0;
return (str);
}
SV * sisyphus () {
char * str;
SV * outsv;
int i;
int l;
l = 20000;
srand (time ((time_t) NULL));
New(1, str, l * sizeof(char), char);
if(str == NULL)
croak("Failed to allocate memory in sisyphus()");
for (i = 0; i < l; i ++) {
str [i] = rand () % 256;
}
outsv = newSVpv(str, l);
Safefree(str);
return outsv;
}
SV * sisyphus2 () {
SV * outsv;
char c;
int i;
int l = 20000;
outsv = NEWSV(0, l);
srand (time ((time_t) NULL));
for (i = 0; i < l; i ++) {
c = rand () % 256;
sv_insert(outsv, i, 1, &c, 1);
}
SvPOK_on(outsv);
SvCUR_set(outsv, l);
return outsv;
}
EOC
$s1 = abigail();
print length($s1), "\n";
$s2 = sisyphus();
print length($s2), "\n";
$s3 = sisyphus2();
print length($s3), "\n";
timethese(500, {
's1' => '$s1 = abigail();',
's2' => '$s2 = sisyphus();',
's3' => '$s3 = sisyphus2();',
}),
__END__
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Fri, 5 Nov 2004 10:03:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Spurious "Use of uninitialized value" with -w, redux
Message-Id: <slrncon924.gvj.tadmc@magna.augustmail.com>
samwyse <dejanews@email.com> wrote:
> As I previously posted, I will try to reduce the program to something
> smaller that reproduces the error. This might take a while because the
> program is parsing AIX-specific files and removing the system
> dependencies could be, hmmm, fun.
There is a high probability that the problem will reveal itself
to you as you go through the exercise described above.
Which is why the Posting Guidelines suggest such an exercise. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 5 Nov 2004 13:46:18 -0500
From: "Marcus" <lumbus@ludd.luth.se>
Subject: Win32::OLE msxml collection problem
Message-Id: <eTPid.38607$T_.7339@bignews4.bellsouth.net>
This is probably a stupid questions since I'm a beginner in Win32::OLE and
Perl...
In the code below I can get the length from $members, but the next line
outputs:
"member array name: Win32::OLE=HASH(0x1825090)->Item(0)->{text}"
code:
$members = $object->getElementsByTagName("BriefDescription");
print "$members->{length}\n";
print "member array name: $members->Item(0)->{text}\n";
I don't think there's anything wrong with $members itself, since the below
will print the value I'm looking for:
foreach my $tmp (in ($members)) {
print "member name: $tmp->{text}\n";
}
Thanks!!
Marcus
------------------------------
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 7365
***************************************