[25717] in Perl-Users-Digest
Perl-Users Digest, Issue: 7957 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 9 09:05:36 2005
Date: Sat, 9 Apr 2005 06:05:15 -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 Sat, 9 Apr 2005 Volume: 10 Number: 7957
Today's topics:
Re: $line = <FH> returns incomplete lines rbric@adomain.com
Re: A menu using framebuffer <joe@inwap.com>
Conditional constant in regular expression (Fritz Bayer)
Re: Conditional constant in regular expression <noreply@gunnar.cc>
Re: finding the first match in a string <tadmc@augustmail.com>
Re: finding the first match in a string <nobull@mail.com>
joining arrays inside hash (justme)
Re: joining arrays inside hash <nobull@mail.com>
Re: joining arrays inside hash axel@white-eagle.invalid.uk
Re: Not able to connect to oracle db using DBI ( Active debhatta@hotmail.com
Re: Not able to connect to oracle db using DBI ( Active debhatta@hotmail.com
Re: Perl Embed in C++ Problem -> Urgent, please help! rbric@adomain.com
Re: Perl on TRIPOD hosted sites..file uploading questio <wdflannery@aol.com>
Re: Q: // and "magic" <nospam-abuse@ilyaz.org>
Re: Start a program and get a hold of it's STDOUT and S <snail@localhost.com>
Re: Start a program and get a hold of it's STDOUT and S <snail@localhost.com>
Re: Start a program and get a hold of it's STDOUT and S (Anno Siegel)
Re: YARQ - Yet another regex question rbric@adomain.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 08 Apr 2005 22:33:36 -0700
From: rbric@adomain.com
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <jrpe51p7i3cmogn75hfi9qjml3orsrl3h4@4ax.com>
On Thu, 07 Apr 2005 01:52:04 -0700, robic@yahoo.com wrote:
>On Thu, 07 Apr 2005 03:10:35 -0500, axel@white-eagle.invalid.uk wrote:
>
>>robic0@yahoo.com wrote:
>>> On Fri, 01 Apr 2005 19:19:35 +0000, Brian McCauley <nobull@mail.com>
>>>>robic0@yahoo.com wrote:
>>
>>>>> $line = '';
>>>>> while(1) {
>>>>> while ( ($line .= <MYLOG> ) )
>>>>> {
>>>>> if ($line =~ /[\n]+/) {
>>>>> print ("GOT THIS: ",$line);
>>>>> $line = '';
>>>>> }
>>>>> }
>>>>> seek (MYLOG,0, 1);
>>>>> sleep (1);
>>>>> }
>>
>>>>That code will hang busy if a partial line is read.
>>
>>> The "while( wait_for_level2_io )" condition is the "<>" mode default.
>>> Perl submits a default Level 2 io read request, then waits for the io
>>> device to deliver a complete entry, which could include more than
>>
>>In your code as soon as an 'incomplete line' (i.e. a line which is not
>>terminated by \n) is read, the code will loop continuously in the inner
>>while loop since the condition will evaluate to true until finally
>>a \n is read and $line reset to ''.
>
>I don't think so, I think <MYLOG> will always advance the read pointer
>but you may be right in as much as the EOF condition will not be
>cleared causing an immediate return due to EOF (a few cycles).
>To fix it:
> while ($line.=<MYLOG>) {
> ......
> seek (MYLOG,0,1);
> }
> sleep(1);
>
>So now its not a looping wait, its a stop wait.....
>
Perl best:: loop { test for EOF ( get data } sleep } }
In essence thats all it is for what you are doing, and its
real-time.
There seems to be alot of purported experts here on
os IO subsystems. But I can tell you after doing Telnet
and terminal emulation code for over 20 years, they are lost
in the weeds...
gluck!
>>
>>> one "\n" depending on if the callers process was slowed down.
>>> Perl would return on the last EOL char it gets (there could be
>>> several) OR the EOF condition. Thats why /\n+/ is relavent.
>>
>>It will return on the _next_ EOL character (or EOF condition).
>>
>I don't believe this is true at all... This is a complex io
>issue Perl has to optimise without wich could cause race
>conditions. To find out do the tests..... level 1 io writer vs
>level 2 reader, where writer has high priority. Try it out.
>
>>> Printing a string with several \n I guess you wouldn't be able
>>> to tell. Might have to run an assembly program that pumps
>>> multiple \n at high priority to tell for sure.
>>
>>If the data creating program prints several \n characters in the same
>>print operation, this reading script will then read several lines.
>>
>In one print statement...
>>Axel
>>
>>
------------------------------
Date: Sat, 09 Apr 2005 04:06:17 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: A menu using framebuffer
Message-Id: <qYydnbEsq6a3KsrfRVn-vA@comcast.com>
Anno Siegel wrote:
> <aulne2002@yahoo.ca> wrote in comp.lang.perl.misc:
>> 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 ?
>
> Check out Curses::UI on CPAN.
But that's a text-based menu system, not a graphical menu system.
-Joe
------------------------------
Date: 9 Apr 2005 03:08:50 -0700
From: fritz-bayer@web.de (Fritz Bayer)
Subject: Conditional constant in regular expression
Message-Id: <a9c0aa9e.0504090208.58a6a979@posting.google.com>
Hello,
I have a URL and I would like to extract the domain, path and query
part by applying only A SINGLE regular expression.
What makes the problem challenging is that I want to preprend a
constant to each capturing group, if and only if, the value is non
null.
So for example the following strings should yield the following
output:
http://www.example.com/path/index.html
domain: www.example.com path: path
http://www.example.com/path/index.html?somekey=value
domain: www.example.com path: path query: somekey=value
http://www.example.com/
domain: www.example.com
The words "domain:", "path:" and "query:" are the constants, which
should be prepended if a capturing group in non empty.
Is there a single regular expression, which can solve this problem? I
don't want to depend on any perl, java or on any other code.
Fritz
------------------------------
Date: Sat, 09 Apr 2005 12:48:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Conditional constant in regular expression
Message-Id: <3bpqihF6j7653U1@individual.net>
Fritz Bayer wrote:
> I have a URL and I would like to extract the domain, path and query
> part by applying only A SINGLE regular expression.
>
> What makes the problem challenging is that I want to preprend a
> constant to each capturing group, if and only if, the value is non
> null.
<snip>
> Is there a single regular expression, which can solve this problem?
No.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 8 Apr 2005 21:45:16 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: finding the first match in a string
Message-Id: <slrnd5egds.2rq.tadmc@magna.augustmail.com>
size14feet@gmail.com <size14feet@gmail.com> wrote:
> I have a string. I have several patterns to match for. I'd like
> to determine which pattern finds a match in the string first & at what
> position.
>
> Anyone have an elegant way to do this?
--------------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $string = 'foo TX bar 12345 baz 98765-1234';
my %patterns = (
street => qr/\d+\s+.*/,
zip => qr/\d{5}(-\d{4})?/,
state => qr/\b[A-Z][A-Z]\b/,
);
print "$string\n";
print "01234567890123456789\n";
foreach my $type ( keys %patterns ) {
print "$type at ", length($1), "\n" if $string =~ /(.*?)$patterns{$type}/;
}
--------------------------------
Making note of the lowest value of length($1) is left as
an exercise for the reader.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Apr 2005 00:49:29 -0700
From: "nobull@mail.com" <nobull@mail.com>
Subject: Re: finding the first match in a string
Message-Id: <1113032969.037097.31560@o13g2000cwo.googlegroups.com>
size14feet@gmail.com wrote:
> I have a string. I have several patterns to match for. I'd like
> to determine which pattern finds a match in the string first &
> at what position.
You want the special variable @-
You have to make sure the patterns themselves contain no capturing
(...) but they can, of course, contain grouping parentheses (?:...).
if ( /(pat1)|(pat2)|(pat3)/ ) {
print "Pattern $#- matched at position $-[0]\n";
}
Note because of the way the regex engine works this may be
significantly less efficient than checking each pattern separately in a
loop if you have a large number of patterns.
------------------------------
Date: 8 Apr 2005 20:14:26 -0700
From: mik3l3374@gmail.com (justme)
Subject: joining arrays inside hash
Message-Id: <e3202a16.0504081914.373e386d@posting.google.com>
hi
i have a hash with a few arrays as elements
eg
%hash = ( 1 => ("A", "B"),
2 => ("C", "D"),
3 => ("E","F"),
4 => ("G","H"),
5 => ("1","2"),
6 => ("one","two");
}
These array elements are longer strings, but i just put it here for
short as ABCD....
I wish to join up the first 4 array elements such that its output is
like this
AE, AF, BE,BF, CG , CH , DG,DH. ( key 1 and 3 will join, key 2 and 4
will join)
Then after that, the result will join with elements of key 5 and 6
(AE,AF,"1","one") , (BE,BF,"1","one"),
(AE,AF,"2","two"),(BE,BF,"2","two"), and so on ...
Can someone suggest a good algorithm to do this?
thanks..
------------------------------
Date: 9 Apr 2005 00:29:38 -0700
From: "nobull@mail.com" <nobull@mail.com>
Subject: Re: joining arrays inside hash
Message-Id: <1113031778.238904.313320@z14g2000cwz.googlegroups.com>
justme wrote:
> i have a hash with a few arrays as elements
No you don't. The elements of a hash are scalars. A scalar can be an
array _reference_.
> %hash = ( 1 => ("A", "B"),
> 2 => ("C", "D"),
> 3 => ("E","F"),
> 4 => ("G","H"),
> 5 => ("1","2"),
> 6 => ("one","two");
> }
That is
%hash = ( 1 => "A",
B => 2,
C => "D",
3 => "E",
F => 4,
# etc...
You mean
%hash = ( 1 => ["A", "B"],
2 => ["C", "D"],
3 => ["E","F"],
4 => ["G","H"],
5 => ["1","2"],
6 => ["one","two"],
);
> These array elements are longer strings, but i just put it here for
> short as ABCD....
> I wish to join up the first 4 array elements such that its output is
> like this
> AE, AF, BE,BF, CG , CH , DG,DH. ( key 1 and 3 will join, key 2 and 4
> will join)
>
> Then after that, the result will join with elements of key 5 and 6
> (AE,AF,"1","one") , (BE,BF,"1","one"),
> (AE,AF,"2","two"),(BE,BF,"2","two"), and so on ...
> Can someone suggest a good algorithm to do this?
Not. There doesn't seem much of a to be a pattern to what you want do
all you so I all I can suggest is just do it. To come up with an
algorithm would imply deciding how it would extend.
------------------------------
Date: Sat, 09 Apr 2005 02:57:15 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: joining arrays inside hash
Message-Id: <Acqdne6m5JFGF8rfRVn-vQ@adelphia.com>
justme <mik3l3374@gmail.com> wrote:
> i have a hash with a few arrays as elements
> eg
> %hash = ( 1 => ("A", "B"),
> 2 => ("C", "D"),
> 3 => ("E","F"),
> 4 => ("G","H"),
> 5 => ("1","2"),
> 6 => ("one","two");
> }
No you don't. You would, if the syntax were correct, have a hash whose
keys would be 1, "B", "C", 3, "F"...
Did you perhaps mean anonymous arrays as in
%hash = ( 1 => [ "A", "B"], ... );
> These array elements are longer strings, but i just put it here for
> short as ABCD....
> I wish to join up the first 4 array elements such that its output is
> like this
> AE, AF, BE,BF, CG , CH , DG,DH. ( key 1 and 3 will join, key 2 and 4
> will join)
> Then after that, the result will join with elements of key 5 and 6
> (AE,AF,"1","one") , (BE,BF,"1","one"),
> (AE,AF,"2","two"),(BE,BF,"2","two"), and so on ...
> Can someone suggest a good algorithm to do this?
Just loop through the data. For example the following loops will create
the AE, AF, BE, ... sequence.
for my $i ( 1..2 ) {
for my $j ( 0..1 ) {
for my $k ( 0..1 ) {
print $hash{$i}->[$j] . $hash{$i + 2}->[$k];
}
}
}
You will need to save the values created instead of printing
them and then run another loop to create the final results desired.
Axel
------------------------------
Date: 9 Apr 2005 00:10:04 -0700
From: debhatta@hotmail.com
Subject: Re: Not able to connect to oracle db using DBI ( Activestate )
Message-Id: <1113030604.721069.218260@o13g2000cwo.googlegroups.com>
Hi,
Thanks for your answers, but do not know why the following is coming on
my machine:
ppm> search DBD-Oracle
Searching in Active Repositories
No matches for 'DBD-Oracle'; see 'help search'.
ppm>
Although someone above has indicated that he could get it.
------------------------------
Date: 9 Apr 2005 00:32:54 -0700
From: debhatta@hotmail.com
Subject: Re: Not able to connect to oracle db using DBI ( Activestate )
Message-Id: <1113031974.672984.234140@g14g2000cwa.googlegroups.com>
Also ,
ppm> install ftp://ftp.esoftmatic.com/outgoing/DBI/5.8.3/DBD-Oracle.ppd
Error: Failed to download URL
ftp://ftp.esoftmatic.com/outgoing/DBI/5.8.3/DBD-Or
acle.ppd: 500 LWP::Protocol::MyFTP: connect: Unknown error
ppm> install ftp://ftp.esoftmatic.com/outgoing/DBI/5.8.2/DBD-Oracle.ppd
Error: Failed to download URL
ftp://ftp.esoftmatic.com/outgoing/DBI/5.8.2/DBD-Or
acle.ppd: 500 LWP::Protocol::MyFTP: connect: Unknown error
ppm>
Can someone give me the correct link ?
------------------------------
Date: Fri, 08 Apr 2005 23:31:41 -0700
From: rbric@adomain.com
Subject: Re: Perl Embed in C++ Problem -> Urgent, please help!
Message-Id: <jhte51h8kncckijsdhi9tktib5enfqadc1@4ax.com>
On 4 Apr 2005 19:38:41 -0700, sleepymish@gmail.com wrote:
>
>A. Sinan Unur wrote:
>> sleepymish@gmail.com wrote in
>> news:1112666053.244718.252350@l41g2000cwc.googlegroups.com:
>>
>> > I was referring to what Tad McClellan said.
>> >
>> > """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
>>
>> Please do not make up weird quoting styles.
>
>Sorry about that, I'm new to posting in google.
>
>
>
>
>> /* embed.cc */
>>
>> #ifdef __cplusplus
>> extern "C" {
>> #include <EXTERN.h>
>> #include <perl.h>
>> static PerlInterpreter *my_perl;
>> }
>> #endif
>>
>
>This worked! I included the #ifdef...#endif block in my code and
>everything compiled!
>
Lots of things compile, but .....
did the perl interpreter work inside the binary at runtime the same
when compiled in C? Well now, let me see, code written for C
just needs to be re-compiled for C++ without change.... hmmm
>Thanks!
------------------------------
Date: 8 Apr 2005 18:23:41 -0700
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <1113009821.663378.75020@l41g2000cwc.googlegroups.com>
>>>>From the Tripod CGI documentation.
Well, my hat's off to ya!
wdf
------------------------------
Date: Sat, 9 Apr 2005 09:02:26 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Q: // and "magic"
Message-Id: <d385n2$2r0u$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Chris Mattern
<matternc@comcast.net>], who wrote in article <icWdnVCkIts8Us_fRVn-jQ@comcast.com>:
> >> So, does anyone find this behavior useful? I've never intentionally
> >> used it, and I can't imagine doing so in the future.
> > At the risk of sounding like an AOLer, I am curious as well. I tried
> > thinking of a way to use this feature. Couldn't think of anything, but
> > that is probably a reflection of my limitations :)
> If you have an "untaint this" regexp, you might wind up using several
> times in a row on several variables.
IIRC, the original reason for this (extremely counter-productive)
misfeature is a simplification of something-to-perl translator (sed,
or awk?). It MIGHT have had some usability before REx-object were
implemented; I expect that now it has none.
Hope this helps,
Ilya
------------------------------
Date: Sat, 9 Apr 2005 01:41:15 -0700
From: "Snail" <snail@localhost.com>
Subject: Re: Start a program and get a hold of it's STDOUT and STDIN?
Message-Id: <d384ai$j63$1@news.astound.net>
axel@white-eagle.invalid.uk wrote:
> Snail <snail@localhost.com> wrote:
>> Hello. I am trying to write a logging program to wrap around a server
>> program that we need that doesn't have logging capabilities of it's
>> own. Normally, one would just redirect it on the command line:
>
>> ./server 2>&1 logfile.log
>
>> But this doesn't have any dating what so ever and it can get hard to
>> read as it grows.
>>
>> My goal is to start the program from my program and get both it's
>> STDOUT/ERR and STDIN, that way my program can see live Output as it
>> comes in from the server and also respond to certain events (the
>> server accepts console commands when it is normally run in the
>> foreground, so it can be fully interactive, accepting command via
>> STDIN normally.
>
> Does the wrapper program actually need to process any commands before
> they are passed to the server? If not...
>
> $ ./server 2>&1 | wrapper_prog
No, my wrapper needs to process OUTPUT coming FROM the server
(STDOUT/ERR of server.) I also want my wrapper be able to SEND commands
TO the server (STDIN os server.)
Would IPC::Open3 be good for this? And using IO::Select for seeing
whether OUT or ERR has data coming from the server? Is this a good
approach?
------------------------------
Date: Sat, 9 Apr 2005 01:43:00 -0700
From: "Snail" <snail@localhost.com>
Subject: Re: Start a program and get a hold of it's STDOUT and STDIN?
Message-Id: <d384dq$j85$1@news.astound.net>
Anno Siegel wrote:
> Snail <snail@localhost.com> wrote in comp.lang.perl.misc:
>> Hello. I am trying to write a logging program to wrap around a server
>> program that we need that doesn't have logging capabilities of it's
>> own. Normally, one would just redirect it on the command line:
>>
>> ./server 2>&1 logfile.log
>>
>> But this doesn't have any dating what so ever and it can get hard to
>> read as it grows.
>>
>> My goal is to start the program from my program and get both it's
>> STDOUT/ERR and STDIN, that way my program can see live Output as it
>> comes in from the server and also respond to certain events (the
>> server accepts console commands when it is normally run in the
>> foreground, so it can be fully interactive, accepting command via
>> STDIN normally.
>>
>> I've been search all over (perldoc, google, etc) and all I could find
>> was examples of getting STDIN or STDOUT (using pipes) but not both at
>> the same time. Further mode, I need this to be in real time (when the
>> server spits out something to STDOUT/ERR I want my program to
>> immediately get this, and then process it (add a line to the log
>> file, perform some processing if a certain event occurs, such has a
>> new connection, etc.)
>
> perldoc IPC::Open2. If that doesn't cut it, see Expect.pm on CPAN.
Sorry if I wasn't clear. I need to be able ot get output (from STDOUT of
server) from server in real time, and sometimes I may want to send a
command to the server (to STDIN of server) from my wrapper.
Thanks.
------------------------------
Date: 9 Apr 2005 11:19:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Start a program and get a hold of it's STDOUT and STDIN?
Message-Id: <d38dnd$ohq$1@mamenchi.zrz.TU-Berlin.DE>
Snail <snail@localhost.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Snail <snail@localhost.com> wrote in comp.lang.perl.misc:
> >> Hello. I am trying to write a logging program to wrap around a server
> >> program that we need that doesn't have logging capabilities of it's
> >> own. Normally, one would just redirect it on the command line:
[...]
> > perldoc IPC::Open2. If that doesn't cut it, see Expect.pm on CPAN.
>
> Sorry if I wasn't clear. I need to be able ot get output (from STDOUT of
> server) from server in real time, and sometimes I may want to send a
> command to the server (to STDIN of server) from my wrapper.
You made that clear enough. Those modules can help you in doing it.
Anno
------------------------------
Date: Fri, 08 Apr 2005 23:13:27 -0700
From: rbric@adomain.com
Subject: Re: YARQ - Yet another regex question
Message-Id: <u4re51dcvfi331rkb9fn45b7g91kg4jt43@4ax.com>
On Tue, 29 Mar 2005 18:37:50 GMT, sjp <salvador@progressivetrail.org>
wrote:
>Hi folks,
>
>I'm parsing through a series of delimited records. Some of the records
>use '\t' for the delimiter, and others use '=09' as the delimiter. My
>program handles the tab-delimited records fine, but records that use '=09'
>have erroneous line breaks after '=' signs, like so:
>
>93=093=094/1/2004=09=09HARNEY=09JAMES=09808 SITKA AVE=09=09NEWBERG=09OR=099=
>71320000=098.33=09I=09CA=09PARK RANGER=09=0966.64=09=09=09=09=09=09PARKS & =
>RECREATION DIVISION=09
>
Thats funny, I see "09" but I don't see "\n" or even (\n=) crfl 13,10
Some "line-breaks" are 10, some are crlf. '10' or '13' is not an
ESCape character as is not the '09', but isint '=09' a representative
printable string of an ESCape sequence? But don't see '1013'.
When do you process these records? Is it in its binary form?
Regex only knows a few '\letter" escape control codes.
You may want to go strictly hex representation of '\n' (even though
its not visible here) by having either the \x0a or \x0d with the '='.
while ($line =~ s/(=\x0a\0d|=[\x0a\x0d])//) {};
I write it this way, without the 'g' modifyer because I don't think
'backtracking' is done in this case since there are no quatifiyers,
that could be your problem.
for a quick test, try this:
while ($line =~ s/=\n//) {};
gluck!!
>I'd like to remove the '=' and EOL, but 'Sline =~ s/\=\n//g;' fails with
>an "Can't modify constant item in substitution (s///) at
>/usr/local/bin/mailparse line 18, near "s/\=\n//g;" error
>
>What is the proper way to do it?
>
>Thanks,
>
>SJP
------------------------------
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 7957
***************************************