[23839] in Perl-Users-Digest
Perl-Users Digest, Issue: 6042 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 22:16:46 2004
Date: Thu, 29 Jan 2004 19:11:14 -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 Thu, 29 Jan 2004 Volume: 10 Number: 6042
Today's topics:
read from a named pipe? <mikee@mikee.ath.cx>
Re: read from a named pipe? <krisajenkins@yahoo.co.uk>
Re: read from a named pipe? <mikee@mikee.ath.cx>
Re: read from a named pipe? <billyoc@gnuyork.org>
Re: read from a named pipe? <jwillmore@remove.adelphia.net>
Re: read from a named pipe? <krisajenkins@yahoo.co.uk>
Re: Really Stumped hour routine <spamblock@nodomain.nodomain.us>
Re: Really Stumped hour routine <gnari@simnet.is>
reg expr. question (newbie-intermediate) <robin@csf.edu>
Re: reg expr. question (newbie-intermediate) <tassilo.parseval@rwth-aachen.de>
Re: Regexp *-operator and multiple elements (Charles DeRykus)
Re: Regular Expression assistance <steve@nospamdunnhq.com>
Re: Regular Expression assistance <matthew.garrish@sympatico.ca>
regular expression no match on set if subset matches (Dave)
Re: regular expression no match on set if subset matche <no_spam_for_jkeen@verizon.net>
Re: regular expression no match on set if subset matche <pinyaj@rpi.edu>
Re: regular expression no match on set if subset matche <noreply@gunnar.cc>
Re: regular expression no match on set if subset matche (Dave)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 30 Dec 2003 13:28:49 -0000
From: Mike <mikee@mikee.ath.cx>
Subject: read from a named pipe?
Message-Id: <vv2vch2qf8lubc@corp.supernews.com>
If a named pipe is created with mknod or mkfifo, how do you read
from the pipe? I've tried:
open(FIFO, '< /tmp/.fifo');
while(<FIFO>) {
...
}
close FIFO;
but it doesn't seem to work.
Mike
------------------------------
Date: Tue, 30 Dec 2003 13:40:42 +0000
From: Kris Jenkins <krisajenkins@yahoo.co.uk>
Subject: Re: read from a named pipe?
Message-Id: <3ff18035$0$11169$cc9e4d1f@news.dial.pipex.com>
Mike wrote:
> If a named pipe is created with mknod or mkfifo, how do you read
> from the pipe? I've tried:
>
> open(FIFO, '< /tmp/.fifo');
> while(<FIFO>) {
> ...
> }
> close FIFO;
>
> but it doesn't seem to work.
>
> Mike
What happens when you do:
open(FIFO, '< /tmp/.fifo') or die( "Error: $!\n" );
?
Kris
------------------------------
Date: Tue, 30 Dec 2003 13:46:44 -0000
From: Mike <mikee@mikee.ath.cx>
Subject: Re: read from a named pipe?
Message-Id: <vv30e49589tif2@corp.supernews.com>
In article <3ff18035$0$11169$cc9e4d1f@news.dial.pipex.com>, Kris Jenkins wrote:
> Mike wrote:
>> If a named pipe is created with mknod or mkfifo, how do you read
>> from the pipe? I've tried:
>>
>> open(FIFO, '< /tmp/.fifo');
>> while(<FIFO>) {
>> ...
>> }
>> close FIFO;
>>
>> but it doesn't seem to work.
>>
>> Mike
>
> What happens when you do:
>
> open(FIFO, '< /tmp/.fifo') or die( "Error: $!\n" );
>
> ?
>
> Kris
This simply hangs. No output, no errors:
#!/usr/bin/perl
# test reading from a fifo
open(FIFO, '< /tmp/.syslog.fifo')
or die "$0: error reading from '/tmp/.syslog.fifo': $!";
$_ = <FIFO>;
close FIFO;
------------------------------
Date: Tue, 30 Dec 2003 14:47:25 GMT
From: Billy O'Connor <billyoc@gnuyork.org>
Subject: Re: read from a named pipe?
Message-Id: <874qvi9xuz.fsf@dps11.gnuyork.org>
Mike <mikee@mikee.ath.cx> writes:
> If a named pipe is created with mknod or mkfifo, how do you read
> from the pipe? I've tried:
>
> open(FIFO, '< /tmp/.fifo');
> while(<FIFO>) {
> ...
> }
> close FIFO;
>
> but it doesn't seem to work.
What's the error, Mike?
------------------------------
Date: Tue, 30 Dec 2003 15:29:30 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: read from a named pipe?
Message-Id: <20031230102929.2bc162a7.jwillmore@remove.adelphia.net>
On Tue, 30 Dec 2003 13:46:44 -0000
Mike <mikee@mikee.ath.cx> wrote:
> In article <3ff18035$0$11169$cc9e4d1f@news.dial.pipex.com>, Kris
> Jenkins wrote:
> > Mike wrote:
> >> If a named pipe is created with mknod or mkfifo, how do you read
> >> from the pipe? I've tried:
<snip>
> > What happens when you do:
> >
> > open(FIFO, '< /tmp/.fifo') or die( "Error: $!\n" ); ?
> >
>
> This simply hangs. No output, no errors:
>
> #!/usr/bin/perl
>
> # test reading from a fifo
>
> open(FIFO, '< /tmp/.syslog.fifo')
> or die "$0: error reading from '/tmp/.syslog.fifo': $!";
> $_ = <FIFO>;
> close FIFO;
Below is some code I put together some time ago. It's untested (in
the respect that I didn't test before posting, but it did work some
time ago - I think :-) ). Anyway, a fifo is not like a "normal" file.
It's not read and written to like a typical file. With that in mind,
you need to have a 'while' loop to read the fifo until some condition
is met or the script is terminated. I think it could use some clean
up, but I think it's enough to get you started (or start some thread
on how the code I posted needs to be corrected :-) ).
------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use IO::File;
my $fh;
$SIG{__WARN__} = $SIG{__DIE__} = sub{
print "Opps\n$_[0]\n$!\n";
exit;
};
$SIG{ALRM} = $SIG{INT} = sub{
undef $fh;
print "Caught a signal - Terminating\n";
exit;
};
$fh = new IO::File "/tmp/myfifo";
while(1){
while(my $line = $fh->getline){
print "FIFO: $line";
}
}
exit;
------------------------------------------------------
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Fine day to work off excess energy. Steal something heavy.
------------------------------
Date: Tue, 30 Dec 2003 15:47:46 +0000
From: Kris Jenkins <krisajenkins@yahoo.co.uk>
Subject: Re: read from a named pipe?
Message-Id: <3ff19dfd$0$2769$cc9e4d1f@news.dial.pipex.com>
Mike wrote:
> In article <3ff18035$0$11169$cc9e4d1f@news.dial.pipex.com>, Kris Jenkins wrote:
>
>>Mike wrote:
>>
>>>If a named pipe is created with mknod or mkfifo, how do you read
>>>from the pipe? I've tried:
>>>
>>>open(FIFO, '< /tmp/.fifo');
>>>while(<FIFO>) {
>>> ...
>>>}
>>>close FIFO;
>>>
>>>but it doesn't seem to work.
>>>
>>>Mike
>>
>>What happens when you do:
>>
>>open(FIFO, '< /tmp/.fifo') or die( "Error: $!\n" );
>>
>>?
>>
>>Kris
>
>
> This simply hangs. No output, no errors:
>
> #!/usr/bin/perl
>
> # test reading from a fifo
>
> open(FIFO, '< /tmp/.syslog.fifo')
> or die "$0: error reading from '/tmp/.syslog.fifo': $!";
> $_ = <FIFO>;
> close FIFO;
Sounds like a blocking read - this script is waiting for something to
read, but it's not showing up - are you sure the process behind the
named pipe is doing something?
Try:
$ tail -f /tmp/.syslog.fifo
If that hangs, then your reader is probably okay, and it's your writer
that's dubious.
(If you're new to named pipes, take a look at perlipc, under the header
'named pipes')
Kris
------------------------------
Date: Mon, 19 Jan 2004 20:02:33 +0000
From: Bruce Horrocks <spamblock@nodomain.nodomain.us>
Subject: Re: Really Stumped hour routine
Message-Id: <aiKv7+CZfDDAFwzC@nodomain.nodomain.us>
In message <bueqqi$qe1$1@news.simnet.is>, gnari <gnari@simnet.is> writes
>you still dont get it
Are you sure? :-)
>there would of course be no point in reading the params into a hash or
>array structure if you still access them as scalars one by one. as soon
>as you have the values in a sensible structures, many ways suggest
>themselves to solve the problem.
You are referring to a post that I wrote in response to a follow-up post
from Gunnar Hjalmarsson. Please do not use it as an argument against my
original post as that would be to take it out of context.
>the $q->Vars solution is not the only one. did you see the proposal by
>A. Sinan Unur in news:ML3f9HEN8ZCAFw65@nodomain.nodomain.us where the
>form values are read directly into a suitable hash of arrays structure?
I did. His is a model answer: helpful and non-condescending to the OP.
My point is not about the quality of the solutions offered but the way
in which they were offered: namely four posts in a row that were being
condescending to the OP when he was doing his best (IMHO).
Ted sums things up neatly in a later post, namely:
>The OP presented it optimized for easy understanding, the followups
>presented it optimized for processing.
>
>Since he wanted an implementation, the progression was already heading
>in the Right Direction, towards a working implementation.
>
>It was _constructive_ criticism, he wasn't going about it the best way.
Whether the first few responses were constructive criticism or not is
now a matter of opinion so I suggest that we let it lie.
I hope that I have at least caused people to think even if they don't
agree.
Regards,
--
Bruce Horrocks
Surrey
England
<firstname>@<surname>.plus.com -- fix the obvious for email
------------------------------
Date: Tue, 20 Jan 2004 00:30:45 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Really Stumped hour routine
Message-Id: <buht14$68g$1@news.simnet.is>
"Bruce Horrocks" <spamblock@nodomain.nodomain.us> wrote in message
news:aiKv7+CZfDDAFwzC@nodomain.nodomain.us...
>
> My point is not about the quality of the solutions offered but the way
> in which they were offered: namely four posts in a row that were being
> condescending to the OP when he was doing his best (IMHO).
about the four in a row, remember there is a propagation time-lag
effect here, so these 4 had probably not seen the other answers
when they wrote theirs.
these answers did not at all sound condescending in my opinion,
but it would be interesting to hear the OP's opinion on this.
also: the fact that so many replied with similar reactions should be
a hint that the point they make is valid, isn't it?
> Whether the first few responses were constructive criticism or not is
> now a matter of opinion so I suggest that we let it lie.
fine with me.
>
> I hope that I have at least caused people to think even if they don't
> agree.
who cares?
I sometimes answer questions here when it strikes my fancy. I do not
really care if some sensitive souls get rubbed the wrong way by
the way I choose to try to help.
gnari
------------------------------
Date: Thu, 22 Jan 2004 00:13:56 -0700
From: "Robin" <robin@csf.edu>
Subject: reg expr. question (newbie-intermediate)
Message-Id: <bunu51$71u$1@reader2.nmix.net>
How would I match all the html tags except for one?
Thanks.
cc to robin@csf.edu if you wouldn't mind.
--
Regards,
Robin
--
robin@csf.edu
--
------------------------------
Date: 22 Jan 2004 07:29:51 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: reg expr. question (newbie-intermediate)
Message-Id: <bunu5f$75r$1@nets3.rz.RWTH-Aachen.DE>
[ posted and mailed ]
Also sprach Robin:
> How would I match all the html tags except for one?
Not with a regexp as your Subject implies. The CPAN has many HTML
modules in store for that. HTML::Parser for instance and some others
that have been built on top of it (such as HTML::TokeParser).
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Tue, 30 Dec 2003 15:17:10 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Regexp *-operator and multiple elements
Message-Id: <HqprsM.5Ax@news.boeing.com>
In article <pL_Hb.75652$Jh.57047@amsnews03.chello.com>,
Martijn Houtman <tinus@tinus.ath.cx> wrote:
>Hello,
>
>I have an issue parsing a string with a regular exression. Here's a small
>example:
>
>@foobar = ("foobarbarbarfoo" =~ m/(foo)(bar)*(foo)/g);
>
>this makes the array foobar contain:
> {"foo", "bar", "foo"}
>while I want it to be
> {"foo", "bar", "bar", "bar", "foo"}
>
>The *-operator seems to 'forget' the first few elements and just returns the
>last element, which is stored in the $2 variable. Is there a way to make it
>return the full list of elements?
>
>I have been suggested to split the string into three pieces first, and then
>parse them separately, but I'd still like to do it with a single regular
>expression.
Another possibility:
if ( "foobarbarbarfoo" =~ /^foo(.*?)foo$/g and
(my $match = $1) =~ /^(?:bar)+$/ )
{
@foobar = ('foo', $match =~ /(bar)/g, 'foo');
print join "\n",@foobar;
}
hth,
--
Charles DeRykus
------------------------------
Date: Tue, 30 Dec 2003 13:54:33 -0000
From: "Steve Dunn" <steve@nospamdunnhq.com>
Subject: Re: Regular Expression assistance
Message-Id: <rsfIb.13188$FN.892@newsfep4-winn.server.ntli.net>
"Ragnar Hafstaš" <gnari@simnet.is> wrote in message
news:bspo66$3nl$1@news.simnet.is...
> "Steve Dunn" <steve@nospamdunnhq.com> wrote in message
> news:YKVHb.12565$FN.4552@newsfep4-winn.server.ntli.net...
> > Hi Gnari,
> >
> > "Ragnar Hafstaš" <gnari@simnet.is> wrote in message
> > news:bsp41o$vrp$1@news.simnet.is...
> > > if you can collect the file into one string without linebreaks, you
> > probably
> > > can do a
> > > match with
> > > <([^/].+?[^/])>([^<]+)
> > Thanks for this. It works great although doesn't take into account the
> '<'
> > being on a new-line. It is returning the desired results, but will
break
> if
> > there's any '<' characters in the text (and this 'mark-up' has no
> > escaping(!))
>
> ok. if you collect the string *with* linefeeds, you should be able to
match
> with
> \n<([^/].+?[^/])>([^<]+)
> then you will have to deal with linefeeds in the capture
Many thanks Gnari. I think we're almost there.
>
> by the way, why are you testing for </xxx> and <xxx/> tags?
> i thought you said there were none.
>
There aren't any in the snippet that I'm parsing, but the regex is also
used on larger peices of text that might contain closing tags
> > Message understood. Many thanks for pointing this out and many many
thanks
> > for your help!
>
> you are welcome
>
> gnari
>
Steve.
p.s. Happy New Year!
>
>
------------------------------
Date: Tue, 30 Dec 2003 09:25:11 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Regular Expression assistance
Message-Id: <kVfIb.4796$Vl6.1313507@news20.bellglobal.com>
"Steve Dunn" <steve@nospamdunnhq.com> wrote in message
news:UnSHb.12489$FN.9281@newsfep4-winn.server.ntli.net...
>
> I now need to modify the expression to take into account multi-line
content.
> To give an example, the current expression matches "<DESCRIPTION>OPINION
OF"
> but it needs to match "<DESCRIPTION>OPINION OF 'new line' BRADLEY ARANT,
ET
> AL."
>
You're probably better off "unbust"ing the file first (never checked if
that's actually a technical term, but it is the name of a script we have
where I work). Essentially, you'd just have to write a script to remove
newlines from the file unless the line begins with a top-level tag. You
could then read the file line-by-line with a simple expression like:
m#^<([^>]*)>(.*)(</\1>)?#i
to grab all the data you need. The usefulness, however, will vary depending
on what you are trying to capture and how it is formatted.
Matt
------------------------------
Date: 23 Jan 2004 19:02:24 -0800
From: daverawding@attbi.com (Dave)
Subject: regular expression no match on set if subset matches
Message-Id: <6f89a035.0401231902.30c45a30@posting.google.com>
This may be simple but I can't seem to get a handle on how to do the
following:
I am trying to define a regular expression to validate a password
format so that the password is valid if it contains from 4 to 10
characters except in the one special case where it has the format of
three letters followed by two numbers.
That is, "abc13edl" is fine but "abc13" is not.
Is there a solution to this (using the gnu Java regular expression
package)?
Any help greatly appreciated!
------------------------------
Date: Sat, 24 Jan 2004 03:10:24 GMT
From: "Jim Keenan" <no_spam_for_jkeen@verizon.net>
Subject: Re: regular expression no match on set if subset matches
Message-Id: <AmlQb.328$La5.5@nwrdny01.gnilink.net>
"Dave" <daverawding@attbi.com> wrote in message
news:6f89a035.0401231902.30c45a30@posting.google.com...
>
> Is there a solution to this (using the gnu Java regular expression
> package)?
>
Why are you asking this in a Perl newsgroup if you wish to solve the problem
with Java?
------------------------------
Date: Fri, 23 Jan 2004 22:20:47 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: regular expression no match on set if subset matches
Message-Id: <Pine.SGI.3.96.1040123221733.79923A-100000@vcmr-64.server.rpi.edu>
On 23 Jan 2004, Dave wrote:
>I am trying to define a regular expression to validate a password
>format so that the password is valid if it contains from 4 to 10
>characters except in the one special case where it has the format of
>three letters followed by two numbers.
>
>That is, "abc13edl" is fine but "abc13" is not.
I'd use the following. It assumes passwords are made up of letters and
numbers. Adjust as you see fit.
if ($pwd =~ /^[a-zA-Z0-9]{4,10}$/ and $pwd !~ /^[a-zA-Z]{3}\d{2}$/) {
# it's an ok password
}
If you want it done as ONE regex, I'd suggest:
if ($pwd =~ /^(?![a-zA-Z]{3}\d{2}$)[a-zA-Z0-9]{4,10}$/) {
# it's ok
}
That one makes sure that, at the beginning of the string, we can't match
three letters followed by two digits followed by the end of the string.
If that's not matched, THEN we match our 4-10 characters.
>Is there a solution to this (using the gnu Java regular expression
>package)?
I don't know, I use Perl's regexes, not Java's.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sat, 24 Jan 2004 04:21:52 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regular expression no match on set if subset matches
Message-Id: <busok4$fivkt$1@ID-184292.news.uni-berlin.de>
Dave wrote:
> I am trying to define a regular expression to validate a password
> format so that the password is valid if it contains from 4 to 10
> characters except in the one special case where it has the format
> of three letters followed by two numbers.
>
> That is, "abc13edl" is fine but "abc13" is not.
>
> Is there a solution to this
This uses two regexes:
$_ = 'mypassword';
print "OK\n" if /^\S{4,10}$/ and !/^[a-z]{3}\d{2}$/i;
> (using the gnu Java regular expression package)?
Have no idea. We talk Perl here.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 24 Jan 2004 20:42:50 -0800
From: daverawding@attbi.com (Dave)
Subject: Re: regular expression no match on set if subset matches
Message-Id: <6f89a035.0401242042.4ea19321@posting.google.com>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1040123221733.79923A-100000@vcmr-64.server.rpi.edu>...
> On 23 Jan 2004, Dave wrote:
>
> >I am trying to define a regular expression to validate a password
> >format so that the password is valid if it contains from 4 to 10
> >characters except in the one special case where it has the format of
> >three letters followed by two numbers.
> >
> >That is, "abc13edl" is fine but "abc13" is not.
>
> I'd use the following. It assumes passwords are made up of letters and
> numbers. Adjust as you see fit.
>
> if ($pwd =~ /^[a-zA-Z0-9]{4,10}$/ and $pwd !~ /^[a-zA-Z]{3}\d{2}$/) {
> # it's an ok password
> }
>
> If you want it done as ONE regex, I'd suggest:
>
> if ($pwd =~ /^(?![a-zA-Z]{3}\d{2}$)[a-zA-Z0-9]{4,10}$/) {
> # it's ok
> }
>
> That one makes sure that, at the beginning of the string, we can't match
> three letters followed by two digits followed by the end of the string.
> If that's not matched, THEN we match our 4-10 characters.
>
> >Is there a solution to this (using the gnu Java regular expression
> >package)?
>
> I don't know, I use Perl's regexes, not Java's.
The one regex worked (Java called from Oracle plsql). I should have
explained that I posted here since after searching through various
groups for information about this problem, it seemed that this group
was often able to help with this type of situation. It also seemed
that the various languages were pretty much in sync in terms of
regular expressions. I was hoping it wouldn't take something labeled
as 'experimental' such as (?(condition)true|false)...
Anyhow, I apologize for posting in the 'wrong' group, but thanks again
for the help.
------------------------------
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 6042
***************************************