[18425] in Perl-Users-Digest
Perl-Users Digest, Issue: 593 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 30 03:05:51 2001
Date: Fri, 30 Mar 2001 00:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985939513-v10-i593@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 30 Mar 2001 Volume: 10 Number: 593
Today's topics:
Re: add lines from logfile <mischief@velma.motion.net>
Re: add lines from logfile <bmb@ginger.libs.uga.edu>
Re: add lines from logfile <uri@sysarch.com>
Re: Adding Values from an Array <mischief@velma.motion.net>
Re: bash history from perl? <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Better way to Flushing STDOUT? (Anno Siegel)
Re: CGI style - CGI vs "here is" vs ?? <mnemotronic@mind\no-spam/spring.com>
Re: fetch back STDERR outputs <mischief@velma.motion.net>
FREE Computer Training <GRIP@zianet.com>
Re: Funny behavior? (Tad McClellan)
Re: Funny behavior? (Philip Lees)
help w/ SIMPLE expect problem <jimjamjoh@softhome.net>
Re: help w/ SIMPLE expect problem (Bernard El-Hagin)
Re: help!! confuse problem about flow control. <lauren_smith13@hotmail.com>
Re: NT file permissions <Jonathan.L.Ericson@jpl.nasa.gov>
Re: NT file permissions (Gary Perkins)
Re: peculiar regex problem (Philip Lees)
Re: Perl newbie <mischief@velma.motion.net>
Re: Perl vs. Python (Tim Hammerquist)
Reading and writing to a pipe <anurag@proximity.com.au>
Re: Reading and writing to a pipe <uri@sysarch.com>
Re: regexp with multiple \n? (Philip Lees)
Re: splitting (Jay Tilton)
Re: splitting <wyzelli@yahoo.com>
Re: splitting <mischief@velma.motion.net>
X-Forwarded-for vs remote_addr vs remote_ip <mathias@koerber.org>
Re: X-Forwarded-for vs remote_addr vs remote_ip (Tad McClellan)
Re: X-Forwarded-for vs remote_addr vs remote_ip <mathias@koerber.org>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 30 Mar 2001 03:10:18 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: add lines from logfile
Message-Id: <tc7u8qjv82ahce@corp.supernews.com>
brian d foy <comdog@panix.com> wrote:
> In article <3AC34034.DB1D4AD2@chemsoft.de>, Tobias Dresbach
> <td@chemsoft.de> wrote:
>> Hi all,
>> i have a log file like the following:
>> IP-Address Port kbytes
>> 192.168.0.1 53 10
>> 192.168.1.2 21 150
>> how is it possible to add all kbytes from the same port and ip-address?
> heh - this looks like an example from the Stonehenge Learning Perl
> class materials. i've taught it many times saying "suppose
> you wanted to do this". now someone has. cool :)
Personally, I've never had the pleasure of taking any of the
Stonehenge classes, and I've never been asked to total bandwidth
logs of the sort above. I regularly write programs to deal with
similar problems, though.
The same methods apply to RADIUS detailed logs to total login
times and total logins, to web server logs to total the downloads
of certain files or the number of hits on missing pages, to BIND
logs to count how many unapproved queries you get from/for a
particular IP/domain, MTA logs to evaluate rapid hits which could
be spam, and many other problems. That's just in administering a
network of servers!
Perl does admirably in all these tasks, and there are many ways to
use the same techniques for other things. A hash and a while(<>)
loop can do a great many things.
Chris
--
Christopher E. Stith
If they can get you asking the wrong questions, they don't
have to worry about the answers.
-- Thomas Pynchon, Gravity's Rainbow
------------------------------
Date: Thu, 29 Mar 2001 22:27:27 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: add lines from logfile
Message-Id: <Pine.A41.4.21.0103292220560.10354-100000@ginger.libs.uga.edu>
On 29 Mar 2001, Logan Shaw wrote:
> In article <3AC34034.DB1D4AD2@chemsoft.de>,
> Tobias Dresbach <td@chemsoft.de> wrote:
> >IP-Address Port kbytes
> >192.168.0.1 53 10
> >192.168.1.2 21 150
> >how is it possible to add all kbytes from the same port and ip-address?
>
> Here you go:
>
> my ($ip, $port, $kB);
>
> while (<>)
> {
> ($ip, $port, $kB) = split;
> $totals{$ip}{$port} += $kB;
> }
>
> Printing them out is left as an exercise.
Golf?
perl -ane '$h{"@F[0,1]"}+=$F[2]}print"$_:$h{$_}\n"for keys%h;{' logfile
Brad
------------------------------
Date: Fri, 30 Mar 2001 06:31:36 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: add lines from logfile
Message-Id: <x766grydh3.fsf@home.sysarch.com>
>>>>> "BB" == Brad Baxter <bmb@ginger.libs.uga.edu> writes:
BB> Golf?
BB> perl -ane '$h{"@F[0,1]"}+=$F[2]}print"$_:$h{$_}\n"for keys%h;{' logfile
perl -lane '$h{"@F[0,1]"}+=$F[2]}print"$_:$h{$_}"for keys%h;{' logfile
one less (if you count the options)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 30 Mar 2001 02:20:06 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Adding Values from an Array
Message-Id: <tc7ramci0tpub7@corp.supernews.com>
FORM Rookie <m0rejunkmail@home.com> wrote:
> OK here we go again. I need your help.
> Here's what I have:
> %some_things = ($thing1 => "2",
> $thing2 => "4");
[snip]
> I need to add the values of $thing1 (2) and $thing2 (4) for a Grand
> Total.
[snip]
my $total = eval join '+', values %foo;
or maybe:
my $total;
for (values %foo) { $total += $_ }
or for the really perverse:
my $total;
$total = (map { $total += $_ } values %foo)[-1];
Those wishing to be even more perverse could rool their
own loop using `each' to get the keys and values, but I
won't show an example of that, because even I have limits
on taste. ;-)
Chris
--
Christopher E. Stith
You can never entirely stop being what you once were. That's
why it's important to be the right person today, and not put
it off till tomorrow. -- Larry Wall, 3rd State of the Onion
------------------------------
Date: 30 Mar 2001 03:09:39 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: bash history from perl?
Message-Id: <86r8zg54wc.fsf@jon_ericson.jpl.nasa.gov>
bismuti@cs.fsu.edu (Peter Bismuti) writes:
> I tried writing a script that executed the 'history' command and
> parsed the output. What I discovered is that the history command is
> a bash command, there is no binary file, no /bin/history or
> /usr/bin/history. I can't figure out any way of executing it from within
> perl, `` don't work. Reading in the .bash_history command directly
> doesn't work either since the history is cached and what is in the file
> does not represent the current history, but what the history was the
> last time a shell exited ( I believe ).
This is more of a bash question than a perl question. Have you tried
the bash documentation and forums?
Jon
------------------------------
Date: 30 Mar 2001 07:54:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Better way to Flushing STDOUT?
Message-Id: <9a1e48$9uu$1@mamenchi.zrz.TU-Berlin.DE>
According to Bernie Cosell <bernie@fantasyfarm.com>:
> Ilmari Karonen <iltzu@sci.invalid> wrote:
>
> } In article <3AC0F6FC.48D60A15@interbulletin.com>, Hon-Chi Ng wrote:
> } >
> } >I would like to flush any buffered output in STDOUT at a given point in my
> } >Perl script, is
> } >
> } > $old_autoflush = $|; $| = 1; print ""; $| = $old_autoflush;
> }
> } {local $| = 1}
>
> Doesn't quite work: you need the print to actually make the flush happen:
> {local $| = 1; print ""}
> does the job.
One might think so, but setting $| to true flushes the file immediately.
See perlvar.
Anno
------------------------------
Date: Thu, 29 Mar 2001 21:58:24 -0700
From: pt <mnemotronic@mind\no-spam/spring.com>
Subject: Re: CGI style - CGI vs "here is" vs ??
Message-Id: <3AC41270.AB729DCC@mindspring.com>
My original post was improperly worded. I could have been more precise on my
use of "CGI.pm" rather than "services of a CGI". Several folks managed to guess
what I was trying to get at, and my thanks to them. Sorry for the confusion and
snittyness on my part. I get that way after repeated blows to the head (forehead
vs. desk).
Remove the obvious anti-spam to reply.
------------------------------
Date: Fri, 30 Mar 2001 02:36:23 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: fetch back STDERR outputs
Message-Id: <tc7s97g9ccub68@corp.supernews.com>
Rick Delaney <rick.delaney@home.com> wrote:
> Mark Jason Dominus wrote:
>> 'use warnings' does not work properly in 5.6.0 with regard to 'only
>> once' warnings.
> That's a pretty sweeping generalization.
Not really. According to the p5p list, `use warnings' can leak up
from a module to the main program. If you use a module which
enables the `use warnings' pragma, don't enable `use warnings'
in your main program, and then have a used-once variable, you
may get a warning.
Here's an example:
# /usr/local/bin/perl
use logged_exec;
$foo = 1;
Name "main::foo" used only once: possible typo at - line 2 (#1)
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention
it again somehow to suppress the message. The our declaration is
provided for this purpose.
This didn't seem to happen if I declared the variable with `my'. It
does if I declare it with `our' or if I don't declare it at all --
which, of course, doesn't pass strictures anyway, and we all use
strictures all the time, right? ;-)
Chris
--
Christopher E. Stith
Parking for people we like only. All other vehicles will be vandalized.
------------------------------
Date: Thu, 29 Mar 2001 23:29:03 -0700
From: "Kevin B. Fast" <GRIP@zianet.com>
Subject: FREE Computer Training
Message-Id: <3AC427AF.3AF1BE21@zianet.com>
This is a multi-part message in MIME format.
--------------064E507BE308E2087D497A79
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
We are a nonprofit youth serving organization
that trains teens to enter the workforce. We
have decided to make our training available
to EVERYONE in an effort to close the gap
between the unfilled IT jobs now available
and those who have the skills to fill them.
If you want certification in Information
Technology ie: MCSE, A+, Cisco Expert
etc. please follow the link below.
Professional quality Computer-Based
Instruction and interactive practice tests.
http://www.zianet.com/GRIP/IT4FREE.html
CODE: 2020
(you need this code to register)
--------------064E507BE308E2087D497A79
Content-Type: text/x-vcard; charset=us-ascii;
name="GRIP.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Kevin B. Fast
Content-Disposition: attachment;
filename="GRIP.vcf"
begin:vcard
n:Fast;Kevin
x-mozilla-html:FALSE
org:GRIP
adr:;;www.zianet.com\GRIP;;;;
version:2.1
email;internet:GRIP@zianet.com
title:Executive Director
fn:Kevin B. Fast
end:vcard
--------------064E507BE308E2087D497A79--
------------------------------
Date: Thu, 29 Mar 2001 21:57:14 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Funny behavior?
Message-Id: <slrn9c7tga.mp1.tadmc@tadmc26.august.net>
Adam Moore <adam@foo.sweet.as> wrote:
>>> No problem. However if I do this:
>>> sub foo {
>>> my $test = <<END
^
^ you should put a semicolon there
>>> Some garbage in here, blah, blah
>>> END
>you might like to
>use something like the following instead:
>
> my $test = q{
> some garbage
> };
But that is not equivalent to Adam's here-doc, for that you would
need double quotes:
my $test = qq{
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 30 Mar 2001 07:28:14 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Funny behavior?
Message-Id: <3ac434e2.66734238@news.grnet.gr>
On Fri, 30 Mar 2001 01:51:16 -0000, Chris Stith
<mischief@velma.motion.net> wrote:
>perldoc -q HERE
>
>You are supposed to check the FAQ before posting.
Have you actually tried this? Sure, the here doc faq is in there, but
way, way down towards the end after a number of totally irrelevant
things such as:
Where can I get a list of Larry Wall witticisms?
If I tried that first off I would assume that perldoc was broken.
Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Fri, 30 Mar 2001 05:04:28 GMT
From: Kris Gonzalez <jimjamjoh@softhome.net>
Subject: help w/ SIMPLE expect problem
Message-Id: <3AC4136E.8A4BC75C@softhome.net>
i have the following simple perl script which accepts user input and
puts the user input to a file, creating the file if it does not exist
and appending to it if it does:
#!/usr/bin/perl
print "Enter password: ";
$pass = <STDIN>;
chomp ($pass);
open (FILE, ">>/tmp/test.txt");
print FILE "$pass\n";
close (FILE);
i can interact with the script fine by invoking it from the shell, and
it produces expected results...however, when trying to interact w/ the
script via expect, the expect script does not appear to be sending
information to the perl script (no file is created if it does not exist,
or else nothing is appended to it if it does exist) although the "Enter
password: " statement from the perl script is echoed to the terminal (so
i know it's actually invoking the perl script). here is the expect
script:
#!/usr/bin/expect
spawn /tmp/test.pl
expect "password"
send "pass\r"
this *should* write "pass" to the file /tmp/test.txt, and does when the
perl script is invoked from the shell and information is input from the
user, but nothing is written to the file when invoked from this expect
script...
any ideas???
------------------------------
Date: Fri, 30 Mar 2001 05:41:40 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: help w/ SIMPLE expect problem
Message-Id: <slrn9c872m.2of.bernard.el-hagin@gdndev32.lido-tech>
On Fri, 30 Mar 2001 05:04:28 GMT, Kris Gonzalez <jimjamjoh@softhome.net>
wrote:
>i have the following simple perl script which accepts user input and
>puts the user input to a file, creating the file if it does not exist
>and appending to it if it does:
>
>#!/usr/bin/perl
>print "Enter password: ";
>$pass = <STDIN>;
>chomp ($pass);
>open (FILE, ">>/tmp/test.txt");
>print FILE "$pass\n";
>close (FILE);
>
>i can interact with the script fine by invoking it from the shell, and
>it produces expected results...however, when trying to interact w/ the
>script via expect, the expect script does not appear to be sending
>information to the perl script
[snip]
In other words, this is not a Perl question.
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Fri, 30 Mar 2001 04:41:09 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: help!! confuse problem about flow control.
Message-Id: <F7Uw6.1123$oQ5.340551@paloalto-snr1.gtei.net>
<nobull@mail.com> wrote in message
news:u9hf0c4yfk.fsf@wcl-l.bham.ac.uk...
> "Lauren Smith" <lauren_smith13@hotmail.com> writes carelessly:
>
> And insert 'do'.
>
> > open (FILE, "/tmp/a") or {print STDERR "can not open"; exit (1);}
>
> Does not compile.
>
> > > how can i write more commands instead of "die" in one line
??
> >
> > Use brackets to define blocks.
>
> And use 'do' to put a BLOCK in a context where an EXPR is expected.
:-) Thanks, it's been quite a while since I've posted here. I've
forgotten quite a bit.
Lauren
------------------------------
Date: 30 Mar 2001 03:01:03 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: NT file permissions
Message-Id: <86vgos55ao.fsf@jon_ericson.jpl.nasa.gov>
garyp@bgm.com.au (Gary Perkins) writes:
> I'm a bit of a newbie to perl but am trying. I have installed the
> Oracle Apache based http server on one of our NT machines and am
> trying to run a perl cgi script to display a list of files in a
> directory on another server (within the same NT domain). This script
> runs fine from the command prompt but fails from the browser. Look
> like a permissions thing to me. I tried to get the apache service to
> run under another username but it wont even start.
This is not really a perl problem. You're going to have to figure out
what username the script will be run under, what permissions that user
has and what permissions the script needs. If you find that you _do_
have a perl problem, post a small, self-contained script that exhibits
the problem, a set of input data and the expected output. Have you
talked to people you work with about the problem?
Jon
------------------------------
Date: Fri, 30 Mar 2001 04:16:32 GMT
From: garyp@bgm.com.au (Gary Perkins)
Subject: Re: NT file permissions
Message-Id: <3ac40838.17596882@wa.nnrp.telstra.net>
Thank you Jon, this appears to be the case. The log file gives me
'Cannot opendir .' yet I can from a command prompt on the server. So
now I guess I need an apache guru or pointer to the appropriate
newsgroup.
Cheers
GP
On 30 Mar 2001 03:01:03 +0000, Jon Ericson
<Jonathan.L.Ericson@jpl.nasa.gov> wrote:
>garyp@bgm.com.au (Gary Perkins) writes:
>
>> I'm a bit of a newbie to perl but am trying. I have installed the
>> Oracle Apache based http server on one of our NT machines and am
>> trying to run a perl cgi script to display a list of files in a
>> directory on another server (within the same NT domain). This script
>> runs fine from the command prompt but fails from the browser. Look
>> like a permissions thing to me. I tried to get the apache service to
>> run under another username but it wont even start.
>
>This is not really a perl problem. You're going to have to figure out
>what username the script will be run under, what permissions that user
>has and what permissions the script needs. If you find that you _do_
>have a perl problem, post a small, self-contained script that exhibits
>the problem, a set of input data and the expected output. Have you
>talked to people you work with about the problem?
>
>Jon
------------------------------
Date: Fri, 30 Mar 2001 06:51:55 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: peculiar regex problem
Message-Id: <3ac42c5a.64550839@news.grnet.gr>
On Thu, 29 Mar 2001 07:15:51 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:
>Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>>On Thu, 29 Mar 2001 10:55:35 +0930, "Wyzelli" <wyzelli@yahoo.com>
>>wrote:
>>
>>>"Kevin Connor Arpe" <kca@po.cwru.edu> wrote in message
>>>news:3AC28827.10AA@po.cwru.edu...
>
>>>> I want to remove (from a string) all instances of useless HTML tags,
>>>> i.e., <tag>whitespace</tag>.
>>>
>>>$data =~ s/<[^>]+>\s*<\/[^>]+>//g;
>>>
>>
>>Or, assuming you only want to remove _matching_ tags, i.e. not
>><tag1></tag2>:
>>
>>s/<([^>]+)>\s*<\/\1>//g;
>
>
>which will fail for something like:
>
> <tag attr="value"> </tag>
>
>and both approaches fail for:
>
> <tag attr=">>value<<"> </tag>
Fair enough. I assumed the OP just wanted to strip out the garbage
tags that something like MS Front Page strews liberally throughout its
HTML. Of course, for more complex stuff one should use the appropriate
module.
Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Fri, 30 Mar 2001 02:40:27 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Perl newbie
Message-Id: <tc7sgr64qde714@corp.supernews.com>
yc <leongyc@tp.edu.sg> wrote:
[ Jeopardectomy (toppostectomy) performed. Please do not top post.]
> "Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
> news:slrn9c3ajs.a84.rgarciasuarez@rafael.kazibao.net...
>> yc wrote in comp.lang.perl.misc:
>> > Hi,
>> >
>> > I'm new and trying to learn perl.
[snip problem and solution]
>> Post-scriptum: For your enjoyment, and to enlighten you about the
>> obsfuscative powers of Perl's conciseness, here's a one-line version
>> of your script:
>> perl -alnF: -e 'print$F[0]' File
> Hi Rafael,
> Thanks for your enlightenment.
> How can I learn obsfuscative powers of Perl ?
Most one-liners come from a healthy amount of experience with
the Perl language and a good understanding of perl's command-line
options. While the former may take a while, the latter can be
had by studying `perldoc perlrun'.
Chris
--
Christopher E. Stith
For the pleasure of others, please adhere to the following
rules when visiting your park:
No swimming. No fishing. No flying kites. No frisbees.
No audio equipment. Stay off grass. No pets. No running.
------------------------------
Date: Fri, 30 Mar 2001 06:06:07 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Perl vs. Python
Message-Id: <slrn9c88rc.tp5.tim@vegeta.ath.cx>
Bryan Coon <bcoon@sequenom.com> wrote:
> Hi, I am looking for information on which language is better for web
> development.
Ahh. Web development. If the site you work with is hosted by an ISP
and not your employer, the administrator is much more likely to _have_
Perl installed.
[ snip ]
> Can anyone offer insight on how Python deals with the things I work
> with, and what are the pros and cons for perl/python on this kind of
> programming?
>
> Sorry for the kind of vague nature of the question, Im just looking for
> some input from anyone who has experience doing these things in both
> languages.
As you discovered, Perl has (so far) a larger following and a larger
support system. This is by no means set in stone, and may change at any
time, but it might be a point for you to consider.
As another post suggested, try Python yourself. I happen to like Python
very much, but there are certain things that I like to do in Python, and
certain things that I wouldn't dream of doing in anything but Perl.
> P.S. (Sorry for using the PY word in the perl newsgroup)
A much bigger crime ;) than mentioning the Py* word in clpm is thinking
that any one language is generally "better" than another. Every
language has its strengths and its weaknesses, and much of this is
decided in the eyes of the programmer.
So without further preaching, I'll leave off with:
1. Try Python yourself.
2. Don't trust our opinions; most of us are arrogant, opinionated,
and closed-minded. I certainly know I am. =)
My tuppence.
--
-Tim Hammerquist <timmy@cpan.org>
guru, n:
A computer owner who can read the manual.
------------------------------
Date: Fri, 30 Mar 2001 13:45:44 +1000
From: Anurag Sharma <anurag@proximity.com.au>
Subject: Reading and writing to a pipe
Message-Id: <3AC40168.5050602@proximity.com.au>
Hello All,
I need to run a program in a different process and then provide input to
its stdin and read out put from its stdout and stderr. Now I know I can
do it using open3 and have managed to do it successfully... however
sometimes the connection runs into problems and I get the message
"resource temporarily unavailable" when I try to write to the stdin.
I have a suspicion that open3 call is not very stable when the process
at the other end tries to read and write at the same time.
Is there something else, more reliable than open3, which will serve my
purpose. I have heard of Comm.pl, but will that allow me to write to
stdin of another process and read from stdout and stderr of that process.
Many thanks in advance.
Kind regards,
Anurag
------------------------------
Date: Fri, 30 Mar 2001 06:54:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading and writing to a pipe
Message-Id: <x73dbvycex.fsf@home.sysarch.com>
>>>>> "AS" == Anurag Sharma <anurag@proximity.com.au> writes:
AS> I need to run a program in a different process and then provide
AS> input to its stdin and read out put from its stdout and
AS> stderr. Now I know I can do it using open3 and have managed to do
AS> it successfully... however sometimes the connection runs into
AS> problems and I get the message "resource temporarily unavailable"
AS> when I try to write to the stdin. I have a suspicion that open3
AS> call is not very stable when the process at the other end tries to
AS> read and write at the same time.
it is not the other process's fault most likely, but yours. you have to
be careful about buffer management when using stuff like open3 on a
process. if the process falls behind in consuming data you feed it, your
pipe will block. and if you then keep trying to read output from the
process and you don't get any, you can deadlock.
AS> Is there something else, more reliable than open3, which will
AS> serve my purpose. I have heard of Comm.pl, but will that allow me
AS> to write to stdin of another process and read from stdout and
AS> stderr of that process.
look into using event.pm and callbacks to handle when you can do
i/o. then you won't block and you will always remain active.
you always have to be aware about how your perl program and the
subprocess interact.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 30 Mar 2001 07:12:47 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: regexp with multiple \n?
Message-Id: <3ac43139.65797712@news.grnet.gr>
>Mark Grimshaw wrote:
>
> I'm capturing input from a FORMs-based bulletin board. If $message is
> my input from the form, I use the following to remove all occurrences of
> \n and replace them with <BR> for return to the browser:
>
> $message =~ s/\n/<BR>/g;
>
> This works fine.
>
> However, to stop users hitting their return key multiple times and
> thereby wasting a lot of space on the webpage, I tried the following
> hoping that it would replace multiple occurrences of \n with <P> and
> then single occurrences of \n with <BR>:
>
> $message =~ s/(\n){2,}/<P>/g;
> $message =~ s/\n/<BR>/g;
>
> However, the first code produces no result. Any solutions?
It works for me:
my $message = "Hello\nworld.\n\n\nHello\n\nworld.\n!";
$message =~ s/(\n){2,}/<P>/g;
$message =~ s/\n/<BR>/g;
print "$message\n";
# output: Hello<BR>world.<P>Hello<P>world.<BR>!
Maybe you should check what's actually in your $message variable when
it hits the regex.
By the way, you don't need the parens around the \n.
Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Fri, 30 Mar 2001 02:11:54 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: splitting
Message-Id: <3ac3e9f5.67707964@news.erols.com>
On Fri, 30 Mar 2001 01:55:10 GMT, Borgy <no@spam.com> wrote:
>See this is the problem I have. When the cookie is written to file I get
>the following all one one line:
>
>1:19.99:Abba Greatest Hits 1:17.99:Blondie Parallel Lines
>
>There are three elements to each part: quantity, price and product. The
>problem I am having is getting a line return after the first part. I need
>to split it up like so:
>
>1:19.99:Abba Greatest Hits
>1:17.99:Blondie Parallel Lines
>
>The fact that there is no delimeter at the end of the first, ie. after the
>first CD, is screwing me up. Question simply put is how to I get a file
>like the second example out of the first.
Whoever is writing the cookie must have a way to parse it once
written. Ask them.
If you are the one writing the cookie and you're trying to figure out
how to parse it, change the way it's written so there's some kind of
separator between fields.
Failing all else, split on the first space before the third colon.
Simple matter of programming.
------------------------------
Date: Fri, 30 Mar 2001 12:01:26 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: splitting
Message-Id: <V0Sw6.11$vZ1.4086@vic.nntp.telstra.net>
"Borgy" <no@spam.com> wrote in message
news:3AC3E76D.4C7A03A4@spam.com...
> See this is the problem I have. When the cookie is written to file I
get
> the following all one one line:
>
> 1:19.99:Abba Greatest Hits 1:17.99:Blondie Parallel Lines
>
> There are three elements to each part: quantity, price and product.
The
> problem I am having is getting a line return after the first part. I
need
> to split it up like so:
>
> 1:19.99:Abba Greatest Hits
> 1:17.99:Blondie Parallel Lines
>
> The fact that there is no delimeter at the end of the first, ie. after
the
> first CD, is screwing me up. Question simply put is how to I get a
file
> like the second example out of the first. Thanks very much for the
help
> people :-)
>
Ok, try this...
while (<DATA>){
my ($first, $second) = ($1, $2) if m/(.*)\s+(\d+:.*)/;
print "$first\n$second\n";
}
__END__
1:19.99:Abba Greatest Hits 1:17.99:Blondie Parallel Lines
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub
d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e
);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";
------------------------------
Date: Fri, 30 Mar 2001 03:00:49 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: splitting
Message-Id: <tc7tn1avicpda8@corp.supernews.com>
Borgy <no@spam.com> wrote:
> See this is the problem I have. When the cookie is written to file I get
> the following all one one line:
> 1:19.99:Abba Greatest Hits 1:17.99:Blondie Parallel Lines
> There are three elements to each part: quantity, price and product. The
> problem I am having is getting a line return after the first part. I need
> to split it up like so:
> 1:19.99:Abba Greatest Hits
> 1:17.99:Blondie Parallel Lines
> The fact that there is no delimeter at the end of the first, ie. after the
> first CD, is screwing me up. Question simply put is how to I get a file
> like the second example out of the first. Thanks very much for the help
> people :-)
I'll _assume_ the album title and band name will never match
q{\d+:\d+\.\d+:} in themselves. It'd be very rare that they
would, and would likely break the cookie code as implemented
elsewhere anyway.
This matches all but the last:
my @match = /(\d+:\d+\.\d+:.*?)(?=\d+:\d+\.\d+:.*?)/g;
This pushes onto that the last one:
push( @match, $foo =~ /.*(\d+:\d+\.\d+:.*)$/;
If you'd rather do something besides put them in an array,
you can do that, too.
Here's my quickly tested code and it's output:
############## code ######################
$foo = '1:19.99:Cracker Short Bus 1:17.99:INXS Kick 1:17.99:Tool Tool';
@match = $foo =~ /(\d+:\d+\.\d+:.*?)(?=\d+:\d+\.\d+:.*)/g;
push( @match, $foo =~ /(\d+:\d+\.\d+:.*)$/ );
$foo = '1:19.99:Cracker Short Bus 1:17.99:INXS Kick 1:17.99:Tool Tool';
@match = $foo =~ /(\d+:\d+\.\d+:.*?)(?=\d+:\d+\.\d+:.*)/g;
push( @match, $foo =~ /.*(\d+:\d+\.\d+:.*)$/ );
foreach( @match ) {
print $_ . "\n";
}
############### output #################
1:19.99:Cracker Short Bus
1:17.99:INXS Kick
1:17.99:Tool Tool
######## back to the post ################
If that doesn't work for you for some reason, I'd be interested
to find out why.
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Fri, 30 Mar 2001 11:25:40 +0800
From: Mathias Koerber <mathias@koerber.org>
Subject: X-Forwarded-for vs remote_addr vs remote_ip
Message-Id: <e3v7ctgber2qhi04ua5seajeqjfc40baef@4ax.com>
Could someone point me to some documentation that descibes these 3
headers and the difference between them?
If I want to log the real-user at the other end, which one(s) should I
log?
thanks
------------------------------
Date: Thu, 29 Mar 2001 21:59:47 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: X-Forwarded-for vs remote_addr vs remote_ip
Message-Id: <slrn9c7tl3.mp1.tadmc@tadmc26.august.net>
Mathias Koerber <mathias@koerber.org> wrote:
>Could someone point me to some documentation that descibes these 3
>headers and the difference between them?
>
>If I want to log the real-user at the other end, which one(s) should I
>log?
What is your Perl question?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 30 Mar 2001 15:30:30 +0800
From: Mathias Koerber <mathias@koerber.org>
Subject: Re: X-Forwarded-for vs remote_addr vs remote_ip
Message-Id: <kfd8ct8k1s681hglqhlb7nbkl95sbfh10r@4ax.com>
>What is your Perl question?
Oops. I though I posted this to a diff group. Slip of fingers.
Sorry.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 593
**************************************