[21706] in Perl-Users-Digest
Perl-Users Digest, Issue: 3910 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 3 18:06:16 2002
Date: Thu, 3 Oct 2002 15:05:14 -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 Thu, 3 Oct 2002 Volume: 10 Number: 3910
Today's topics:
Calling a shell from perl without losing control <zeus_riposta@yahoo.com>
Re: Calling a shell from perl without losing control (Malcolm Dew-Jones)
Re: Calling a shell from perl without losing control <goldbb2@earthlink.net>
Re: Calling a shell from perl without losing control <krahnj@acm.org>
Re: Calling a shell from perl without losing control <zeus_riposta@yahoo.com>
Re: Downloading from a www server: Problem <flavell@mail.cern.ch>
Re: How to geta list of perl modules <comdog@panix.com>
Re: IO::Select has limits? or how to use IO::Poll? <goldbb2@earthlink.net>
Re: Mac OS X and Perl 6 <comdog@panix.com>
Re: New Perl Module for QA Engineers <comdog@panix.com>
Re: Odd behavior for variables "a" and "b" <nospam1002@joesbox.cjb.net>
Parse a word into three strings (Ray Frye)
Re: Parse a word into three strings <kurzhalsflasche@netscape.net>
Re: Parse a word into three strings <Tassilo.Parseval@post.rwth-aachen.de>
Re: Parse a word into three strings (Tad McClellan)
Re: Parse a word into three strings <Tassilo.Parseval@post.rwth-aachen.de>
Re: Perl Tutor Wanted - Mtn View, CA (Tad McClellan)
Re: reading Cobol PIC 9(6)V99 formats... (Tad McClellan)
Re: reading Cobol PIC 9(6)V99 formats... <jpagnew@vcu.edu>
Re: reading Cobol PIC 9(6)V99 formats... (Tad McClellan)
Recursive regex <sh@planetquake.com>
Re: Recursive regex <krahnj@acm.org>
Re: Recursive regex <perl-dvd@ldschat.com>
Re: reqex problem <wksmith@optonline.net>
Re: Set many slots in a hash to the same defined value. <goldbb2@earthlink.net>
Re: Unable to trap error from child <goldbb2@earthlink.net>
Re: What is the best way for file/stream IO in Perl? (Peter J. Acklam)
Re: What is the best way for file/stream IO in Perl? <Tassilo.Parseval@post.rwth-aachen.de>
Re: What is the best way for file/stream IO in Perl? (Peter J. Acklam)
Re: Wow! A trivial regexp I can't do! <bart.lateur@pandora.be>
Re: Wow! A trivial regexp I can't do! ctcgag@hotmail.com
Re: || versus OR <asimmons@mitre.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 03 Oct 2002 12:24:07 -0700
From: Zeus <zeus_riposta@yahoo.com>
Subject: Calling a shell from perl without losing control
Message-Id: <3D9C9957.B8BA48F5@yahoo.com>
Hi,
Running a shell(sh, bash, csh etc) from a perl program causes the
control to go to the shell. Perl regains control only if a manual 'exit'
is typed in.
open(FH, "| csh |");
The above statement runs the csh shell and then gives control back to
the perl script. I'd like to go one step further. I'm interested in
executing the shell and run a few shell scripts *within* the shell and
then hand over the control to the perl program.
It could be something like:
open(FH, "| csh |");
system("myprog1.csh");
system("myprog2.csh");
Unfortunately, the above code does not run myprog1.csh and myprog2.csh
*within* the csh shell that is opened.
I'd like to know if this is possible in perl.
Thanks,
Zeus.
------------------------------
Date: 3 Oct 2002 13:56:10 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Calling a shell from perl without losing control
Message-Id: <3d9caeea@news.victoria.tc.ca>
Zeus (zeus_riposta@yahoo.com) wrote:
: Hi,
: Running a shell(sh, bash, csh etc) from a perl program causes the
: control to go to the shell. Perl regains control only if a manual 'exit'
: is typed in.
: open(FH, "| csh |");
: The above statement runs the csh shell and then gives control back to
: the perl script. I'd like to go one step further. I'm interested in
: executing the shell and run a few shell scripts *within* the shell and
: then hand over the control to the perl program.
: It could be something like:
: open(FH, "| csh |");
: system("myprog1.csh");
: system("myprog2.csh");
: Unfortunately, the above code does not run myprog1.csh and myprog2.csh
: *within* the csh shell that is opened.
: I'd like to know if this is possible in perl.
: Thanks,
: Zeus.
I've never used it, but the expect module might be what you want.
Also, I think that using "|csh|" is not what you mean, you probably
want "|csh".
Plus, to send commands to the csh, you send them to the csh's standard
input, which is reading from FH, so what you originaly may have
wanted is (untested code)
open FH , "|csh" or die $!;
print FH "myprog1.csh"
------------------------------
Date: Thu, 03 Oct 2002 17:10:07 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Calling a shell from perl without losing control
Message-Id: <3D9CB22F.FC3F570D@earthlink.net>
Zeus wrote:
>
> Hi,
>
> Running a shell(sh, bash, csh etc) from a perl program causes the
> control to go to the shell. Perl regains control only if a manual
> 'exit' is typed in.
>
> open(FH, "| csh |");
>
> The above statement runs the csh shell and then gives control back to
> the perl script.
I don't think that this does what you think it does.
Perl's open() lets start an external program and write to it, or start a
program and read from it.
You can't (with the open function) start a program and *both* write to
*and* read from it.
Use the IPC::Open2 module, with it's open2() function, to do that.
> I'd like to go one step further. I'm interested in
> executing the shell and run a few shell scripts *within* the shell and
> then hand over the control to the perl program.
>
> It could be something like:
> open(FH, "| csh |");
> system("myprog1.csh");
> system("myprog2.csh");
>
> Unfortunately, the above code does not run myprog1.csh and myprog2.csh
> *within* the csh shell that is opened.
I would call it fortunate that it doesn't. Things would be *very*
screwed up if it did.
> I'd like to know if this is possible in perl.
The closest that you could do would be something like:
open FH, "| csh" or die horribly;
print FH "myprog1.csh\n";
print FH "myprog2.csh\n";
close FH or die horribly;
--
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?
------------------------------
Date: Thu, 03 Oct 2002 21:34:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Calling a shell from perl without losing control
Message-Id: <3D9CB7CA.3FA3C7E8@acm.org>
Zeus wrote:
>
> Running a shell(sh, bash, csh etc) from a perl program causes the
> control to go to the shell. Perl regains control only if a manual 'exit'
> is typed in.
>
> open(FH, "| csh |");
You can't do that! You can either do open(FH, "csh |"); or open(FH, "|
csh"); but not both.
perldoc Expect
perldoc IPC::Open2
perldoc IPC::Open3
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 03 Oct 2002 14:56:04 -0700
From: Zeus <zeus_riposta@yahoo.com>
Subject: Re: Calling a shell from perl without losing control
Message-Id: <3D9CBCF4.4A768641@yahoo.com>
> The closest that you could do would be something like:
> open FH, "| csh" or die horribly;
> print FH "myprog1.csh\n";
> print FH "myprog2.csh\n";
> close FH or die horribly;
>
This does not run myprog1.csh and myprog2.csh from within the opened csh,
which is my requirement.
Zeus.
------------------------------
Date: Thu, 3 Oct 2002 21:34:03 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Downloading from a www server: Problem
Message-Id: <Pine.LNX.4.40.0210032057340.32146-100000@lxplus074.cern.ch>
On Oct 3, Mina Naguib inscribed atop a fullquote:
> LWP is (usually) for perl programs to download files from remote machines.
Agreed...
> This does not seem to be your case.
that was my impression too...
> You want to SEND the file to the
> remote machine. Apache+Perl make this quite convenient for you since
> all the tcp/ip/protocol is already taken care of.. All you have to do is
> tell the client what the type of the content you're sending it is, then
> the content. and presto !
Pretty-much, but I understood the questioner to be wanting to send
multiple products in response to a single purchase order, which is why
I was trying to get a clearer idea of what they really wanted (and a
better idea of their current expertise, to be honest).
> print "Content-type: application/octet-stream\n\n";
It appears that you have in mind to send a zip file. So the proper
thing to do would surely be to say honestly what you're sending,
rather than pretending it's an arbitrary bag of bits about which you
have no further knowledge? Then a properly-behaved web browser can
respond to the content-type by opening the associated helper app,
whatever it might be. That's what the HTTP content-type is designed
for, afrer all (and we don't all flout IETF standards-draft mandates
in the way that one big vendor does, after all...)
But if you're going to use CGI.pm, then how about using it to create
the response header? So (if you use procedural calls), I'd suggest:
print header(-type=>'application/zip');
(or the corresponding OO-type invocation, if you prefer).
> binmode(STDOUT);
Er, yes; if the data is binary, doesn't FH deserve the same?
> while (<FH>) {
> print;
> }
Could do; but line-oriented I/O handling may not be the best choice
for binary files. You have no idea how big the "lines" might turn out
to be. It's usually recommended to sysread() into a fixed-size buffer,
like the later example shown in perlopentut
http://www.perldoc.com/perl5.8.0/pod/perlopentut.html#Binary-Files
all the best
------------------------------
Date: Thu, 03 Oct 2002 16:41:42 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: How to geta list of perl modules
Message-Id: <031020021641427136%comdog@panix.com>
In article <MPG.1804fb78d306445598972d@east.usenetserver.com>, Barry Kimelman <barryk2@delete_me.mts.net> wrote:
> How do you get a list of modules that are installed on your system
> (UNIX or windows) ? I know you can use perldoc to get info on a
> specific module, but I need to get a list of ALL the installed modules.
see my Dr. Dobbs article on the subject:
http://www.ddj.com/documents/s=1498/ddj0105pl/
--
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>
------------------------------
Date: Thu, 03 Oct 2002 16:45:27 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: IO::Select has limits? or how to use IO::Poll?
Message-Id: <3D9CAC67.6D843800@earthlink.net>
Joel Nelson wrote:
>
> I am trying to build both client and server pieces that can be used to
> stress test a server program being written at work. We run these
> scripts under windows (blech)...
>
> The problem with the server piece is that I need to be able to handle
> at least 1024 connections. IO::Select seems to choke at 127
> connections(clients time out),
This is a system imposed limitation; it's not perl's fault, but the
fault of the underlying C function call.
> and I am having trouble trying to use arrays of IO::Select objects.
That's not likely going to work, unless you use timeouts of zero on all
of them... That is, something like:
while( 1 ) {
foreach my $fh ( map $_->can_read(0), @io_select_objects ) {
> I have also taken a look at IO::Poll but I don't understand how to
> use it.
You're assuming that it doesn't suffer from the same limitation as
select... it might. Anyway, assuming it doesn't:
If you have a filehandle which you want to watch for readability, do:
$poll->mask( $fh, POLLIN );
If you have a filehandle which you want to watch for writability, do:
$poll->mask( $fh, POLLOUT );
To watch a handle for both reading and writing:
$poll->mask( $fh, POLLIN|POLLOUT );
To stop watching a handle, do:
$poll->mask( $fh, 0 );
To block until some handles are ready for reading or writing, and to
find out what those handles are, do:
$poll->poll( $timeout );
my @readok = $poll->handles( POLLRDNORM );
my @writeok = $poll->handles( POLLWRNORM );
> Does anyone know how I can handle 1024 connections?
You could create 9 child processes, have each of them handle 113
connections (plus a connection to the parent), and have the children
multiplex data from the clients, and the parent multiplex data from the
children... But this can get kinda ugly.
Possibly you could manage something with some Windows specific function,
perhaps WaitForMultipleObjects ... (I don't pretend to understand all of
the windows APIs... I'm just guessing here).
> Or point me to some good web sites or books that
> cover this? I have Lincoln Steins "Network Programming with Perl" but
> it doesn't go into dealing with this many connections and I can't get
> the IO::Poll example converted to work for me. Help!!!! :-)
>
> The other piece I am writing is a single script that can launch the
> 1024 connections. I'll probably run into the same issues for
> lots-o-connections but I may be able to run the same script multiple
> times in different DOS windows and even on multiple machines. Of
> course, I'd rather not.
If you start your child processes with IPC::Open2, it shouldn't open new
DOS windows -- nor if you start child processes with Win32::Process.
--
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?
------------------------------
Date: Thu, 03 Oct 2002 16:50:29 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: Mac OS X and Perl 6
Message-Id: <031020021650298762%comdog@panix.com>
In article <anfol3$q75$1@reader1.panix.com>, Da Witch <heather710101@yahoo.com> wrote:
> In <864rc4yaow.fsf@red.stonehenge.com> merlyn@stonehenge.com (Randal L. Schwartz) writes:
> >>>>>> "Da" == Da Witch <heather710101@yahoo.com> writes:
> >Da> Somehow I thought that Perl was a lot more committed to Linux than
> >Da> that.
> >Just another data point (in addition to the other items in this thread):
> > I used Perl long before Linux was even around.
> Sloppy writing on my part. I should have written "committed to the
> FSF-ish idea of open, non-proprietary software."
those who make perl can use anything they like and still support open
source software. what people use to do their work and what Perl is
are different things.
--
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>
------------------------------
Date: Thu, 03 Oct 2002 16:45:57 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: New Perl Module for QA Engineers
Message-Id: <031020021645572449%comdog@panix.com>
In article <pkent77tea-258D8A.02021203102002@news-text.blueyonder.co.uk>, pkent <pkent77tea@yahoo.com.tea> wrote:
> In article <021020021125083485%comdog@panix.com>,
> brian d foy <comdog@panix.com> wrote:
> > In article <65fb4119.0210020522.13118b48@posting.google.com>, Rob Marchetti
> > <robert.marchetti@fmr.com> wrote:
> > > S.A.M. is a simple automation module written in Perl that allows a
> > > user to automate Internet Explorer.
> > don't forget to mention that it's only for Windows platforms...
> with but a small look at the code, is there any reason why it cannot
> work on MacOS (classic and X) or the Unix release of IE?
besides its dependence on Win32::OLE?
--
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>
------------------------------
Date: 3 Oct 2002 19:30:50 GMT
From: Josef Drexler <nospam1002@joesbox.cjb.net>
Subject: Re: Odd behavior for variables "a" and "b"
Message-Id: <ani5ta$f64$1@panther.uwo.ca>
Janek Schleicher wrote:
> Tom Ewall wrote at Wed, 02 Oct 2002 23:25:53 +0200:
>> The question is, why the unique behavior with the variables "a" and
>> "b"? We're using Perl 5.6.1 build 630 on Windows 2000. Several of us
>> have tried it and the behavior is consistent on different machines.
>
> Well, $a and $b are in fact global variables.
> From perldoc perlvar:
>
> $a
> $b Special package variables when using sort(), see
> "sort" in perlfunc. Because of this specialness
> $a and $b don't need to be declared (using
> local(), use vars, or our()) even when using the
> strict vars pragma. Don't lexicalize them with
^^^^^^^^^^^^^^^^
> "my $a" or "my $b" if you want to be able to use
> them in the sort() comparison block or function.
You can lexicalize them and still use them in sort, in fact, as long as you
override the lexicalisation by using "our" in the closure passed to sort:
#!/usr/bin/perl -w
use strict;
my @array = (65, 5, 4, -4, 1);
my $a = "Hello";
my $b = "World";
my @sorted = sort {our ($a,$b); $a <=> $b} @array;
print "$a $b: @sorted\n";
------- Output:--------
Hello World: -4 1 4 5 65
This isn't really all that useful though.
--
Josef Drexler | http://publish.uwo.ca/~jdrexler/
---------------------------------+----------------------------------------
Please help Conserve Gravity | Email address is *valid*.
Play Hockey, not Baseball. | Don't remove the "nospam" part.
------------------------------
Date: 3 Oct 2002 12:54:52 -0700
From: radarray@gcioa.org (Ray Frye)
Subject: Parse a word into three strings
Message-Id: <b3359839.0210031154.48334ca4@posting.google.com>
This seems like it should be a novice question. In fact, it is. I
need to take the first character of a string, read it into its own
string, and delete it from the original string. Then I need to take
the next four characters from the original string minus the first
character and read them into another string, and delete them from the
original string.
Say the original string = "E1230UNIFORM"
What I want to end up with is:
$firstChar = "E"
$nextFourChars = "1230"
$theRestOfThe String = "UNIFORM"
I have been fiddling with regular expressions off and on all day and I
get nowhere. Can anyone help?
Ray
------------------------------
Date: Thu, 03 Oct 2002 22:13:57 +0200
From: Dominik Seelow <kurzhalsflasche@netscape.net>
Subject: Re: Parse a word into three strings
Message-Id: <3D9CA505.7030107@netscape.net>
Ray Frye announced:
> This seems like it should be a novice question. In fact, it is. I
> need to take the first character of a string, read it into its own
> string, and delete it from the original string. Then I need to take
> the next four characters from the original string minus the first
> character and read them into another string, and delete them from the
> original string.
>
> Say the original string = "E1230UNIFORM"
> What I want to end up with is:
> $firstChar = "E"
> $nextFourChars = "1230"
> $theRestOfThe String = "UNIFORM"
>
> I have been fiddling with regular expressions off and on all day and I
> get nowhere. Can anyone help?
>
> Ray
why don't you use substr?
use strict;
my $string = "E1230UNIFORM";
my $firstChar=substr($string,0,1);
my $nextFourChars=substr($string,1,4);
my $theRestOfTheString=substr($string,5);
print join (',',$firstChar,$nextFourChars,$theRestOfTheString);
HTH,
Dominik
------------------------------
Date: 3 Oct 2002 20:20:39 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Parse a word into three strings
Message-Id: <ani8qn$clq$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Ray Frye:
> This seems like it should be a novice question. In fact, it is. I
> need to take the first character of a string, read it into its own
> string, and delete it from the original string. Then I need to take
> the next four characters from the original string minus the first
> character and read them into another string, and delete them from the
> original string.
>
> Say the original string = "E1230UNIFORM"
> What I want to end up with is:
> $firstChar = "E"
> $nextFourChars = "1230"
> $theRestOfThe String = "UNIFORM"
>
> I have been fiddling with regular expressions off and on all day and I
> get nowhere. Can anyone help?
Either use substr() as Dominik suggested or something along this line:
my ($first_char, $next_four, $rest) = $string =~ /(.)(....)(.*)/;
A regex in list context returns the matches captured by parens. In the
above, there are three of them that linearly get assigned to the three
variables on the left side.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 03 Oct 2002 20:20:40 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Parse a word into three strings
Message-Id: <slrnapp9it.804.tadmc@magna.augustmail.com>
Ray Frye <radarray@gcioa.org> wrote:
> I have been fiddling with regular expressions off and on all day and I
> get nowhere. Can anyone help?
Assuming the original string is in the $_ variable:
my($firstChar, $nextFourChars, $theRestOfTheString) = m/(.)(....)(.*)/s;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Oct 2002 20:29:46 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Parse a word into three strings
Message-Id: <ani9bq$d1a$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Ray Frye:
> This seems like it should be a novice question. In fact, it is. I
> need to take the first character of a string, read it into its own
> string, and delete it from the original string. Then I need to take
> the next four characters from the original string minus the first
> character and read them into another string, and delete them from the
> original string.
>
> Say the original string = "E1230UNIFORM"
> What I want to end up with is:
> $firstChar = "E"
> $nextFourChars = "1230"
> $theRestOfThe String = "UNIFORM"
>
> I have been fiddling with regular expressions off and on all day and I
> get nowhere. Can anyone help?
Since you have fixed-length records (except for the last) here's yet
another solution using unpack(). This is usually very fast:
my ($first_char, $next_four, $rest) = unpack "a a4 a*", $string;
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 03 Oct 2002 19:34:43 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <slrnapp6m0.7q5.tadmc@magna.augustmail.com>
Vishal Agarwal <avishal@vsnl.net> wrote:
> There's a guy called Randal L. Schwartz.
> Excerpts from his site (http://www.stonehenge.com/merlyn/)
>=========
> Perl Training Classes
> Learn Perl now! To find out about my on-site and open-enrollment
> classes, send a blank message to perl-training-info@stonehenge.com.
> You'll get the answer back by email, so make sure your browser has
> your correct address if you follow this link.
>=========
That is an auto-responder email address. If you'd like to send
email to a human, feel free to use this address:
tad@stonehenge.com
Stonehenge is offering our PROM class in conjunction with
UC Berkeley Extension in San Francisco 10-12 March 2003.
We are also currently working on other Bay Area (and NYC) venues
for public Perl trainings.
--
Tad McClellan tad@stonehenge.com
Director of Sales and Operations
Stonehenge Consulting Services http://www.stonehenge.com/perltraining/
------------------------------
Date: Thu, 03 Oct 2002 19:16:00 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <slrnapoqtk.7bt.tadmc@magna.augustmail.com>
Jim Agnew <jpagnew@vcu.edu> wrote:
> Thank you *ALL* for your kind hints and pointers...
One more hint:
http://www.geocities.com/nnqweb/nquote.html
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 03 Oct 2002 15:43:51 -0400
From: Jim Agnew <jpagnew@vcu.edu>
To: tadmc@augustmail.com
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <3D9C9DF7.6F1EFB@vcu.edu>
Tad McClellan wrote:
>
> Jim Agnew <jpagnew@vcu.edu> wrote:
>
> > Thank you *ALL* for your kind hints and pointers...
>
> One more hint:
>
> http://www.geocities.com/nnqweb/nquote.html
>
> :-)
>
ok, thanks, Tad!! - Jim ;-D
------------------------------
Date: Thu, 03 Oct 2002 20:20:39 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <slrnapp9be.804.tadmc@magna.augustmail.com>
Jim Agnew <jpagnew@vcu.edu> wrote:
> Tad McClellan wrote:
>> Jim Agnew <jpagnew@vcu.edu> wrote:
>>
>> > Thank you *ALL* for your kind hints and pointers...
>>
>> One more hint:
[snip URL about top-posting]
> ok, thanks, Tad!! - Jim ;-D
OK, two _more_ hints then :-) :-)
Don't send stealth Cc's.
See the Posting Guidelines at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 03 Oct 2002 19:53:29 GMT
From: "Sean Hamilton" <sh@planetquake.com>
Subject: Recursive regex
Message-Id: <Ze1n9.39461$bj5.2104735@news2.telusplanet.net>
Greetings,
How would I go about matching the text enclosed within matching curly
braces, even if there are matching curly braces within?
For example...
{blah}
should match "blah"... and
{blah {bleh} bloh}
should match "blah {bleh} bloh".
Also, is there a better way of matching "everything up to" something?
Presently I'm using
[^}]+
However, if I wanted to match a pattern or the like, that wouldn't work.
thanks,
sh
------------------------------
Date: Thu, 03 Oct 2002 21:30:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Recursive regex
Message-Id: <3D9CB6E7.4F8A4EA4@acm.org>
Sean Hamilton wrote:
>
> Greetings,
>
> How would I go about matching the text enclosed within matching curly
> braces, even if there are matching curly braces within?
perldoc -q matching
Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod
How do I find matching/nesting anything?
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 3 Oct 2002 15:30:53 -0600
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Recursive regex
Message-Id: <Fz2n9.368$G5.137@fe01>
> {blah}
>
> should match "blah"... and
>
> {blah {bleh} bloh}
>
> should match "blah {bleh} bloh".
############################################
my @strings = ("{blah}", "{blah {bleh} bloh}");
foreach my $string(@strings){
# match the most outer curlies, find whats between them
$string =~ /^[^{]*{(.*)}[^}]*?$/;
my $results = $1;
print qq^results = "$results"\n^;
}
############################################
Results to this were
############################################
results = "blah"
results = "blah {bleh} bloh"
############################################
> Also, is there a better way of matching "everything up to"
something?
> Presently I'm using
>
> [^}]+
Not really, but if you need to match 0 or more as I did in the example
above, use a * instead of the +
Regards,
David
------------------------------
Date: Thu, 3 Oct 2002 16:11:20 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: reqex problem
Message-Id: <iw1n9.5573$dQ1.193311@news4.srv.hcvlny.cv.net>
"péman" <majortom71@hotmail.com> wrote in message
news:uoZm9.11760$YK4.1342875@e3500-atl2.usenetserver.com...
> Hello, I am currently involved with a small project that requires me to
use
> regex. I am rather new to regex and know some simple forms of it, but I
am
> having trouble doing what I need to do.
>
> I am using PHP to do my work, however I am using the PCRE (Perl Compatible
> RegEx) functions.
> This particular problem involves obtaining unknown (variable length)
> word/words from
> within the middle of a sentence.
> For instance take the sentence:
>
> The dog was happy that the <blank> ate the rat.
>
> where <blank> may be any of the following:
> cat
> snake
> big fat cat
> long scary snake with a chipped tooth
> ...or any other word(s)/phrase
>
> The best I have come up with (with some help) is this:
> <?
> $string="The dog was happy that the big ugly snake ate the rat.";
> preg_match("/the (.+?) ate/",$string,$array);
> $word1 = $array[0];
> echo "$word1<br>";
> ?>
>
> The result of this is:
> the big ugly snake ate
> where in my case I only need "big ugly snake".
>
> More important is:
> if I were to make the sentence
> The dog was happy that thebig ugly snakeate the rat.
>
> How can I pull the "big ugly snake" (no pun intended) out of this mess? It
> sounds weird but I may need to use
> this :(
>
> Well if you can assist me I really do appreciate and if not I still
> appreciate it :)
>
> thanks in advance,
> péman
>
>
>
In Perl, list context does the trick. Sorry if this is not much help in
PHP.
($snake) = "The dog was happy that thebig ugly snakeate the rat."=~ m/The
dog was happy that the(.*)ate the rat./;
Bill
------------------------------
Date: Thu, 03 Oct 2002 17:19:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Set many slots in a hash to the same defined value.
Message-Id: <3D9CB45C.3208C758@earthlink.net>
Teh (tî'pô) wrote:
>
> Say I want to set several key in a hash, if I just want them to exist
> I can say:
> my %hash;
> @hash{qw/a b c/} = ();
>
> but what if I want to set them to a specific value (1 for example),
> the simplest way I can come up with is:
> my %hash;
> my @keys = qw/a b c/;
> @hash{@keys} = split(/ /, "1 "x scalar @keys);
>
> Is there a better way in terms of simplicity and/or efficiency?
One of these three should do it:
$hash{$_} = 1 for @keys;
@hash{@keys} = (1) x @keys;
%hash = map {$_ => 1} @keys;
--
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?
------------------------------
Date: Thu, 03 Oct 2002 17:15:51 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Unable to trap error from child
Message-Id: <3D9CB387.CDE330E3@earthlink.net>
Tom Beer wrote:
[snip]
> $childpid = wait;
> print "$childpid exited with q = $?; x = $!\n";
The $! variable will only be valid if wait() failed. So, do:
if( $childpid = wait ) {
print "wait failed: $!";
} else {
my $sig = $? & 0xff;
my $ret = $? >> 8;
print "$childpid killed by signal $sig\n" if $sig;
print "$childpid exited with code $ret\n" if $ret;
print "$childpid exited successfully\n" if !$?;
}
--
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?
------------------------------
Date: Thu, 03 Oct 2002 18:19:27 GMT
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <d6qrbn7o.fsf@online.no>
"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> One cool thing about IO::File and its derivates is that they can
> be used like an ordinary filehandle:
>
> my $h = IO::File->new;
> $h->open("<file");
> while (<$h>) {
> ...
> }
No check on the output from open() is a bad thing, regardless of
whether IO::File, FileHandle, or the standard open() is used. :-)
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: 3 Oct 2002 20:15:19 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <ani8gn$che$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Peter J. Acklam:
> "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>
>> One cool thing about IO::File and its derivates is that they can
>> be used like an ordinary filehandle:
>>
>> my $h = IO::File->new;
>> $h->open("<file");
>> while (<$h>) {
>> ...
>> }
>
> No check on the output from open() is a bad thing, regardless of
> whether IO::File, FileHandle, or the standard open() is used. :-)
Grrr. See, each time I have to decide whether I bloat my skelleton
examples with error-checking (and thus looking foolish, in a way) or
avoid it for brevity and for focus on the significant stuff and thusly
earn some rants. Dilemma, ain't it? :-)
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 03 Oct 2002 20:47:50 GMT
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <lm5f6yih.fsf@online.no>
"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Also sprach Peter J. Acklam:
>
> > "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> >
> > > my $h = IO::File->new;
> > > $h->open("<file");
> > > while (<$h> ) {
> > > ...
> > > }
> >
> > No check on the output from open() is a bad thing, regardless of
> > whether IO::File, FileHandle, or the standard open() is used. :-)
>
> Grrr. See, each time I have to decide whether I bloat my skelleton
> examples with error-checking (and thus looking foolish, in a way) or
> avoid it for brevity and for focus on the significant stuff and thusly
> earn some rants. Dilemma, ain't it? :-)
I see your point. :-) I tend to do something like
$h->open("<file") or die "...";
just to indicate that the value should be checked.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Thu, 03 Oct 2002 18:08:56 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Wow! A trivial regexp I can't do!
Message-Id: <ts1ppukjhc81r2bo327i5ivihct89omok7@4ax.com>
Arvin Portlock wrote:
>Obviously $string =~ s/\\n+$/\n/; doesn't do it.
$string =~ s/(\\n)+$/\n/;
--
Bart.
------------------------------
Date: 03 Oct 2002 18:25:41 GMT
From: ctcgag@hotmail.com
Subject: Re: Wow! A trivial regexp I can't do!
Message-Id: <20021003142541.230$Nl@newsreader.com>
"Arvin Portlock" <temp133@hotmail.com> wrote:
> I thought I knew regular expressions. But when I tried to do this one
> I was amazed I didn't know how.
>
> I want to replace all occurrences of the string "\n" (that's a backslash
> and an 'n', not a newline) with a newline but only when they occur at
> the end of a string. So I might have the following string:
>
> "This is a line\n\n\n";
If you are writing English, don't put the semicolon there. If you
are writing Perlish, write it the way you would write it in Perl:
'This is a line\n\n\n';
> And I want to replace those last three '\n's with true newlines. I only
> want this to happen when they're at the end of a string though. I know
> how to do it with a while loop, but isn't there some cool way to do it
> with a simple regular expression?
>
> Obviously $string =~ s/\\n+$/\n/; doesn't do it.
# can't use / as delimiter because division inside replacement.
$string =~ s!((?:\\n)+)$!"\n" x ((length $1)/2)!e;
or
1 while $string =~ s/\\n(\n*)$/\n$1/ ;
or
1 while $string =~ s/\\n(?=\n*$)/\n/ ;
or
$string =~ s/\\n(?=(\n|\\n)*$)/\n/g;
For the first, real newlines at the very end will block changes of '\n'
that are immediately before them, for the last ones they won't.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Thu, 3 Oct 2002 17:29:53 -0400
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: || versus OR
Message-Id: <anicri$rr1$1@newslocal.mitre.org>
Here's one that burned me bad once:
##############################
#########
# Test #1--$input_name defined
#########
$input_name = 'Bob';
$name_t1 = $input_name || 'Aaron';
$name_t1_2 = $input_name or 'Aaron';
print "name_t1:$name_t1\n";
print "name_t1_2:$name_t1_2\n";
#########
# Test #2--$input_name2 defined
#########
$name_t2 = $input_name2 || 'Aaron';
$name_t2_2 = $input_name2 or 'Aaron';
print "name_t2:$name_t2\n";
print "name_t2_2:$name_t2_2\n";
##############################
With test#2, $name_t2_2 does not get assigned 'Aaron'
-Aaron
"Bob X" <bobx@linuxmail.org> wrote in message
news:vmNm9.17551$Lg2.4829564@news2.news.adelphia.net...
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3D9BA01D.60E81D3B@acm.org...
> > Bob X wrote:
> <snip>
> > In a list context || has higher precedence than the comma operator while
> > or has lower precence so yes it does matter. :-)
> >
> >
> > John
>
> Can you give me a very short lesson as to how it matters in a list
context?
>
> Bob
>
>
------------------------------
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.
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 3910
***************************************