[9454] in Perl-Users-Digest
Perl-Users Digest, Issue: 3048 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 3 16:07:25 1998
Date: Fri, 3 Jul 98 13:04:06 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 3 Jul 1998 Volume: 8 Number: 3048
Today's topics:
How does one remove ^H metacharacters from STDIN? (Eric Dew)
Re: How does one remove ^H metacharacters from STDIN? <franzen@pmel.noaa.gov>
Re: How does one remove ^H metacharacters from STDIN? (Eric Dew)
Re: How does one remove ^H metacharacters from STDIN? (Craig Berry)
Re: How does one remove ^H metacharacters from STDIN? (Abigail)
Re: how to flush network connections <cliff@mail.genwax.com>
Re: How to get files in a directory? (brian d foy)
Re: How to get files in a directory? <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: How to get files in a directory? <merlyn@stonehenge.com>
Re: How to get files in a directory? (brian d foy)
Re: How to get files in a directory? (Mark-Jason Dominus)
Re: How to get files in a directory? (Josh Kortbein)
Re: HTML pages with Perl (Cameron Laird)
Re: HTML pages with Perl <vlaurent@NOSPAM.ssmhc.com>
Re: HTML pages with Perl <wcjones@fccj.org>
HTTP header: changing the type field <jon@go.co.uk>
Re: I can't nail down the uninitialized value :( <quednauf@nortel.co.uk>
Re: I NEED SOME HELP <perlguy@inlink.com>
Re: i've got a forking problem <boys@aspentech.com>
Re: Invalid regexp in grep s_emery@my-dejanews.com
Re: Invalid regexp in grep (Larry Rosler)
Re: Invalid regexp in grep (Larry Rosler)
Re: Invalid regexp in grep (Charles DeRykus)
Re: Invalid regexp in grep (Larry Rosler)
Re: Invalid regexp in grep <dgris@rand.dimensional.com>
Re: Invalid regexp in grep <dgris@rand.dimensional.com>
Is Perl through CGI enough for this? (David Rouse)
Re: Java and Perl together? <lth@dannet.dk>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 2 Jul 1998 18:39:26 GMT
From: edew@netcom.com (Eric Dew)
Subject: How does one remove ^H metacharacters from STDIN?
Message-Id: <edewEvHD5q.1ss@netcom.com>
Keywords: bouncy mangle melodramatic Nairobi
In my perl script, I have:
print("Enter name: ");
chomp($name=<STDIN>);
. . .
When I enter a name, say, Joe, but I really want to type in
Job, I use the backspace key (equivalent to ^H) to change the "e" to a "b."
But now, even though what I see (if I were to print("$name"); for example)
is Job, it's really Joe^Hb. How do I remove the ^H's?
EDEW
------------------------------
Date: Thu, 2 Jul 1998 12:13:29 -0700
From: Nathan Franzen <franzen@pmel.noaa.gov>
Subject: Re: How does one remove ^H metacharacters from STDIN?
Message-Id: <Pine.SOL.3.96.980702120526.17427B-100000@corona.pmel.noaa.gov>
On Thu, 2 Jul 1998, Eric Dew wrote:
> In my perl script, I have:
> print("Enter name: ");
> chomp($name=<STDIN>);
> . . .
> When I enter a name, say, Joe, but I really want to type in
> Job, I use the backspace key (equivalent to ^H) to change the "e" to a "b."
> But now, even though what I see (if I were to print("$name"); for example)
> is Job, it's really Joe^Hb. How do I remove the ^H's?
I ran into this problem recently as I was reading in a text file
consisting of the saved screen output from someone's session with another
program. I needed to recognize the string 'READ.DATA', and had to deal
with 're^H^HREAD ^H.DATA' and other such disasters
In my program I have the lines:
while (<$fh>) {
while (s/.\010//mg){}; # remove ^H-have to use a while, 'cause of ^H^H
This appears to work well, but I'd be delighted if someone has a better
suggestion. Hmmm, as I look at this now, I'm not sure what the /m is
doing for me...lemme look at the rest of the code...well, anyway, the /m
is not important, but the /g is.
-N
Nathan CM Franzen franzen@pmel.noaa.gov | NOAA/PMEL
(206)-526-4808 | NOAA Western Regional Center
TAO project: | 7600 Sand Point Way NE
http://www.pmel.noaa.gov/toga-tao/ | Seattle WA 98115
------------------------------
Date: Thu, 2 Jul 1998 21:13:35 GMT
From: edew@netcom.com (Eric Dew)
Subject: Re: How does one remove ^H metacharacters from STDIN?
Message-Id: <edewEvHKAn.1Fs@netcom.com>
In article <Pine.SOL.3.96.980702120526.17427B-100000@corona.pmel.noaa.gov> Nathan Franzen <franzen@pmel.noaa.gov> writes:
>On Thu, 2 Jul 1998, Eric Dew wrote:
>
>> In my perl script, I have:
>> print("Enter name: ");
>> chomp($name=<STDIN>);
>> . . .
>> When I enter a name, say, Joe, but I really want to type in
>> Job, I use the backspace key (equivalent to ^H) to change the "e" to a "b."
>> But now, even though what I see (if I were to print("$name"); for example)
>> is Job, it's really Joe^Hb. How do I remove the ^H's?
>
>I ran into this problem recently as I was reading in a text file
>consisting of the saved screen output from someone's session with another
>program. I needed to recognize the string 'READ.DATA', and had to deal
>with 're^H^HREAD ^H.DATA' and other such disasters
>
>In my program I have the lines:
>
> while (<$fh>) {
> while (s/.\010//mg){}; # remove ^H-have to use a while, 'cause of ^H^H
>
>This appears to work well, but I'd be delighted if someone has a better
>suggestion. Hmmm, as I look at this now, I'm not sure what the /m is
>doing for me...lemme look at the rest of the code...well, anyway, the /m
>is not important, but the /g is.
>
>-N
>
>Nathan CM Franzen franzen@pmel.noaa.gov | NOAA/PMEL
> (206)-526-4808 | NOAA Western Regional Center
>TAO project: | 7600 Sand Point Way NE
>http://www.pmel.noaa.gov/toga-tao/ | Seattle WA 98115
>
>
>
Your suggestion worked ok. Here's my refinement:
REMOVEH:{
$word=~s/.\010//; #no global!
redo REMOVEH if $word=~/\010/;
}
The problem with your suggestion was multiple backspaces. Suppose I
typed, Hello World^H^H^H^H^HGirl. I want to get Hello Girl. Your
pattern substitution would yield "Hello WorlGirl".
Thanks for the idea!
EDEW
------------------------------
Date: 2 Jul 1998 21:36:35 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How does one remove ^H metacharacters from STDIN?
Message-Id: <6nguh3$kt5$2@marina.cinenet.net>
Eric Dew (edew@netcom.com) wrote:
: The problem with your suggestion was multiple backspaces. Suppose I
: typed, Hello World^H^H^H^H^HGirl. I want to get Hello Girl. Your
: pattern substitution would yield "Hello WorlGirl".
Here's my refinement that fixes this problem:
1 while s/[^\cH]\cH//g;
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 2 Jul 1998 23:05:15 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: How does one remove ^H metacharacters from STDIN?
Message-Id: <6nh3nb$83p$1@client3.news.psi.net>
Eric Dew (edew@netcom.com) wrote on MDCCLXVI September MCMXCIII in
<URL: news:edewEvHD5q.1ss@netcom.com>:
++ In my perl script, I have:
++ print("Enter name: ");
++ chomp($name=<STDIN>);
++ . . .
++
++ When I enter a name, say, Joe, but I really want to type in
++ Job, I use the backspace key (equivalent to ^H) to change the "e" to a "b."
++ But now, even though what I see (if I were to print("$name"); for example)
++ is Job, it's really Joe^Hb. How do I remove the ^H's?
Perhaps you should be using your erase character (delete by default)
instead?
As for removing ^H's:
1 while s/[^\cH]\cH//g;
s/^\cH+//;
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
------------------------------
Date: Mon, 29 Jun 1998 21:36:14 -0700
From: Cliff Rayman <cliff@mail.genwax.com>
Subject: Re: how to flush network connections
Message-Id: <35986B3E.821933CA@genwax.com>
my $old=select($tcpconnection) ; $|=1; select($old);
Delian Delchev wrote:
> I write a perl script that makes tcp connection to port 25. I need to
> flush all data that is in stream queue, because mail server not respont,
> and then timeout and close connection. How I can flush file descriptor?
>
> --
> Delian Delchev http://www.naturella.com/~delian
> ____ ____ __ ____ _ _ ____ __ __
> / ) / ) / / ) / / / ) / /
> / / /___ / / /___ / /___ / /
> / / / / / / / / / /
> /____/ (____/ /____) (____/ _/ /_ (____/ \___/
------------------------------
Date: Thu, 02 Jul 1998 11:57:15 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to get files in a directory?
Message-Id: <comdog-ya02408000R0207981157150001@news.panix.com>
Keywords: from just another new york perl hacker
In article <359BAB97.9CCFC665@perrier.bmc.uu.se>, m94tne@student.tdb.uu.se posted:
>What is the command for getting (all) files (as a list) in the current
>directory?
perldoc -f opendir
then
perldoc perlfaq
good luck :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>
------------------------------
Date: 02 Jul 1998 17:56:00 +0200
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: How to get files in a directory?
Message-Id: <7xg1gk5jsf.fsf@fidelio.vcpc.univie.ac.at>
Re: How to get files in a directory?, Tobias
<tobbe@perrier.bmc.uu.se> said:
Tobias> Hi, What is the command for getting (all) files (as
Tobias> a list) in the current directory?
map {perldoc -f $_} qw(opendir readdir closedir);
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/
"You see? You see? Your stupid minds! Stupid! Stupid!" ~ Eros, Plan9 fOS.
------------------------------
Date: Thu, 02 Jul 1998 16:36:58 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: How to get files in a directory?
Message-Id: <8cww9wqkf7.fsf@gadget.cscaper.com>
>>>>> "Tony" == Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at> writes:
Tony> Re: How to get files in a directory?, Tobias
Tony> <tobbe@perrier.bmc.uu.se> said:
Tobias> Hi, What is the command for getting (all) files (as
Tobias> a list) in the current directory?
Tony> map {perldoc -f $_} qw(opendir readdir closedir);
In case someone at home thought that was a literal response, it wasn't.
(Not to mention the discouraged "map in void context" problem. :-)
It'd have to be something like:
for (qw(opendir readdir closedir)) {
system "perldoc", "-f", $_;
}
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 60 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Thu, 02 Jul 1998 12:58:03 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to get files in a directory?
Message-Id: <comdog-ya02408000R0207981258030001@news.panix.com>
Keywords: from just another new york perl hacker
In article <8cww9wqkf7.fsf@gadget.cscaper.com>, Randal Schwartz <merlyn@stonehenge.com> posted:
>>>>>> "Tony" == Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at> writes:
>Tony> map {perldoc -f $_} qw(opendir readdir closedir);
>In case someone at home thought that was a literal response, it wasn't.
>(Not to mention the discouraged "map in void context" problem. :-)
>It'd have to be something like:
>
> for (qw(opendir readdir closedir)) {
> system "perldoc", "-f", $_;
> }
sri[161] perl -e 'print map {`perldoc -f $_`} qw(opendir readdir closedir)'
:)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>
------------------------------
Date: 2 Jul 1998 14:31:03 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: How to get files in a directory?
Message-Id: <6ngjl7$aq4$1@monet.op.net>
Keywords: Brahms compressible garner slash
In article <359BAB97.9CCFC665@perrier.bmc.uu.se>,
Tobias Nenkert <m94tne@student.tdb.uu.se> wrote:
>What is the command for getting (all) files (as a list) in the current
>directory?
`readdir'.
------------------------------
Date: 2 Jul 1998 18:40:26 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: How to get files in a directory?
Message-Id: <6ngk6q$s3n$2@news.iastate.edu>
Randal Schwartz (merlyn@stonehenge.com) wrote:
: >>>>> "Tony" == Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at> writes:
: Tony> Re: How to get files in a directory?, Tobias
: Tony> <tobbe@perrier.bmc.uu.se> said:
: Tobias> Hi, What is the command for getting (all) files (as
: Tobias> a list) in the current directory?
: Tony> map {perldoc -f $_} qw(opendir readdir closedir);
: In case someone at home thought that was a literal response, it wasn't.
: (Not to mention the discouraged "map in void context" problem. :-)
But it's soooo cooooooolllllll!
[Why is it considered to be a problem? By all means direct me to
a FAQ if I'm missing it.]
Josh
--
_________________________________________________________
I do not trust your bitch.
- Frederich Nietzche, in _Also Sprach Zarathustra_
------------------------------
Date: 2 Jul 1998 11:14:26 -0500
From: claird@Starbase.NeoSoft.COM (Cameron Laird)
Subject: Re: HTML pages with Perl
Message-Id: <6ngbl2$1co$1@Starbase.NeoSoft.COM>
In article <Pine.GSO.3.96.980627151448.19372B-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>On 27 Jun 1998, mikep wrote:
>
>> The trick is that the first line out of your perl script must be
>> "Content-type: text/html\n\n" (note the two line breaks, don't forget
>> them) if your script is to be a standalone script (e.g. a standalone
>> "page").
>
>That's not necessarily the (whole) truth. For a more complete answer,
>check the docs, FAQs, and newsgroups about CGI programming. Hope this
>helps!
.
.
.
I suspect that even that will help the questioner only obliquely.
My guess is that he's looking for a way to embed Perl functionality
within a (formally) HTML page.
I've collected all the references I know on this subject in <URL:
http://starbase.neosoft.com/~claird/comp.lang.perl.misc/perl_architectures.html#embedded>.
--
Cameron Laird http://starbase.neosoft.com/~claird/home.html
claird@NeoSoft.com +1 713 996 8546 FAX
------------------------------
Date: Wed, 01 Jul 1998 11:32:38 -0500
From: Vince Laurent <vlaurent@NOSPAM.ssmhc.com>
To: Jaap Prins <jaap.prins@mail.which.net>
Subject: Re: HTML pages with Perl
Message-Id: <359A64A6.4EFA287B@NOSPAM.ssmhc.com>
Check out
"Creating Cool Web Pages with Perl" by jerry Muelver
ISBN 0-7645-3018-6
Published by IDG books
Jaap Prins wrote:
> Is it possible to produce an HTML page with a CGI-Perl programme
> using Perl 5.003(!)? If so, How?
------------------------------
Date: Fri, 03 Jul 1998 08:25:12 -0400
From: Bill 'Sneex' Jones <wcjones@fccj.org>
Subject: Re: HTML pages with Perl
Message-Id: <359CCDA8.BBEF4D51@fccj.org>
Vince Laurent wrote:
> Check out
> "Creating Cool Web Pages with Perl" by jerry Muelver
> ISBN 0-7645-3018-6
> Published by IDG books
>
> Jaap Prins wrote:
>
> > Is it possible to produce an HTML page with a CGI-Perl programme
> > using Perl 5.003(!)? If so, How?
Also see CGI.pm and LWP modules - they know HTML better than some
Webmasters!
-Sneex-
____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
mailto:webmaster@fccjmail.fccj.org | http://webmaster.fccj.org/Webmaster
____________________________________________________________________________
Pay attention to your enemies, for they are
the first to discover your mistakes.
------------------------------
Date: Thu, 02 Jul 1998 11:02:58 +0100
From: Jonathan Cavell <jon@go.co.uk>
Subject: HTTP header: changing the type field
Message-Id: <359B5AD2.748506DE@go.co.uk>
Hi all,
I am writing a CGI script that prints out .wav data in audio/x-wav
format. To enable users to click on a link to the CGI program and then
automatically start downloading the sample rather than
responding with 'unknown file extension' I am using the header variable
in the CGI package:
.......
$req = new CGI;
........
$type_string = 'audio/x-wav';
print $req->header(-status=> '202',
-accept_ranges=> 'bytes',
-content_length=> length($sample),
-type=> $type_string,
-content_Transfer_Encoding=> "base64");
print $sample;
........
The problem is that it doesn't work. When I try to downoad the sample in
Netscape I still get the error that the file type was unknown.
Any ideas why this may be?
--
Jonny Cavell, Go Internet.
Telephone 0181 964 1405
------------------------------
Date: Thu, 02 Jul 1998 09:56:27 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: I can't nail down the uninitialized value :(
Message-Id: <359B4B3A.13B4CF70@nortel.co.uk>
Tom Phoenix wrote:
>
> > The solution is to initialize $message{body} = ''; before the SLURP loop.
>
> I don't know that that's _the_ solution. Using a recent version of perl
> would be my preferred solution. :-)
Right, I am using 5.003 (not at home, but I am not going to mess around with the
available network here :) Does that mean that the error message wouldn't come
with 5.004 ? This is cool. However, Jim's solution works for now...
T H A N K S ! !
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: Thu, 2 Jul 1998 11:13:14 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: I NEED SOME HELP
Message-Id: <359B6B4A.456CFEEF@inlink.com>
Will,
There are many of us who would be happy to help answer your questions,
provided you have done a little "homework" yourself.
Most of us in this group have jobs, family, etc... and don't have the
time to take each new Perl programmer under our wings and show them
everything.
Instead, we have created many resources on the WWW that answer 98% of
the questions new Perl programmers may have.
Please go to: http://www.perl.com (Catchy name huh?) On the left side
of the screen, there is a "menu bar" At the bottom of it, there is a
link that reads: "Windows NT" Click it and your Perl and CGI world will
be enlightened.
Good luck, and don't SHOUT when posting questions. I am just getting my
hearing back... ;-)
Brent Michalski
------------------------------
Date: Fri, 03 Jul 1998 11:26:58 +0100
From: Ian Boys <boys@aspentech.com>
Subject: Re: i've got a forking problem
Message-Id: <359CB1F2.2F1C@aspentech.com>
Tom Christiansen wrote:
>
> Here's the private mail I sent:
>
> >> : while (<F>) {
> >> : fork && next;
> >> : print;
> >> : exit;
> >> : }
> >>
> >> You're duplicating stdio buffers. Tsk.
>
> >hunh? first of all, why? stdio has nothing to do with this, i am
> >reading from a filehandle. fine, fork duplicates this filehandle but the
> >child prints out the line and exits without touching the filehandle and
> >the parent process should just continue to read the filehandle where it
> >left off from, right? so, there shouldn't be any problems there, as far
> >as I can figure. second of all, how do i fix that? i have tried to turn
> >off the buffering "$| = 1;" but that didn't help.
>
> Only output buffering is affected by $|, not input buffering. I believe
> you have three different problems here. The input buffers are duplicated.
> The seek pointers are shared and advance together in all processs (but
> buffer consumption doesn't). The scheduling of the different process
> is non-deterministic.
>
I share Dan's confusion about this.
In the code example, all reading from the input file is done in
the parent process. Duplication of input buffers and sharing of
seek pointers with the children should not be an issue. Granted,
the lines may be printed in a non-deterministic order, but one
assumes that is not an issue.
The parent process reads a line from the file and stores it in $_.
The child is forked, producing a copy of $_ in the child as it then
was in the parent. The child prints its private copy of $_ and exits.
Where is the problem?
Indeed, when I run this example with 5.004 under AIX and under HPUX,
it works for me just as expected. And in fact, I get the output in
the right order, but I will take that as a happy accident.
Ian
Sorry
to
put
this
extra
stuff
here
but
otherwise
my
dumb
news
host
keeps
bouncing
the
posting
as
not
having
enough
original
text!
------------------------------
Date: Thu, 02 Jul 1998 14:36:39 GMT
From: s_emery@my-dejanews.com
Subject: Re: Invalid regexp in grep
Message-Id: <6ng5to$oh5$1@nnrp1.dejanews.com>
In article <MPG.10044159bcda5249896e0@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) wrote:
>
> In article <6ne52q$4it$1@nnrp1.dejanews.com> on Wed, 01 Jul 1998 20:10:03
> GMT, s_emery@my-dejanews.com <s_emery@my-dejanews.com> says...
> > I can't seem to grep a certain array because I get an error of invalid
> > regexp.
> >
> > This is the idea of the programming:
> >
> > @a = (1 ,2, 5, 22, 84, 129, 205);
> >
> > @b = grep (/[7-176]/, @a);
> >
> > Which doesn't work because 176 is out of range - the highest number
> > allowed is 99. This is too bad, I hope this is fixed in the future
> > versions of Perl.
>
> You misunderstanmd the use of square brackets in regexes. What you have
> requested is a match against a single character in the range of
> characters between 7 and 1, or a 7, or a 6. The perl compiler complains
> about the invalid range, and refuses to compile the regex.
>
> When you say the hishest number allowed is 99, what you were really
> matching against was a single character in the range of characters
> between 7 and 9, or a 9. This is not what you wanted.
>
> You should not use a regex for this problem. Try the following:
>
> @b = grep 7 <= $_ && $_ <= 176, @a;
>
> When you want to compare numbers, use them as numbers, not as strings.
>
> --
> Larry Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
I tried your method and it worked perfectly fine on a small array. When I
tried it on the array I needed to use it for ($#a = 216,000) it flopped.
No answer was given whatsoever. Why?
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 2 Jul 1998 09:30:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Invalid regexp in grep
Message-Id: <MPG.10055579396f137e9896e1@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <6ng5to$oh5$1@nnrp1.dejanews.com> on Thu, 02 Jul 1998 14:36:39
GMT, s_emery@my-dejanews.com <s_emery@my-dejanews.com> says...
> In article <MPG.10044159bcda5249896e0@nntp.hpl.hp.com>,
> lr@hpl.hp.com (Larry Rosler) wrote:
..
> > @b = grep 7 <= $_ && $_ <= 176, @a;
...
> I tried your method and it worked perfectly fine on a small array. When I
> tried it on the array I needed to use it for ($#a = 216,000) it flopped.
> No answer was given whatsoever. Why?
It sounds like you ran out of memory, though why there was no diagnostic
beats me. I couldn't make mine fail for $#a = 400_000, but maybe my
system has more memory. At $#a = 1_000_000, I got the diagnostic 'Out of
memory!'. It ran very slowly in either case (thrashing the virtual
memory?).
You might try this variation instead:
my @b;
foreach (@a) { push @b, $_ if 7 <= $_ && $_ <= 176 }
That *may* make better use of memory. No guarantees, though. It also
failed for me at 1_000_000.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 2 Jul 1998 13:53:37 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Invalid regexp in grep
Message-Id: <MPG.10059329f633d6979896e2@nntp.hpl.hp.com>
In article <MPG.10055579396f137e9896e1@nntp.hpl.hp.com> on Thu, 2 Jul
1998 09:30:19 -0700, Larry Rosler <lr@hpl.hp.com> says...
> In article <6ng5to$oh5$1@nnrp1.dejanews.com> on Thu, 02 Jul 1998 14:36:39
> GMT, s_emery@my-dejanews.com <s_emery@my-dejanews.com> says...
...
> > I tried your method and it worked perfectly fine on a small array. When I
> > tried it on the array I needed to use it for ($#a = 216,000) it flopped.
> > No answer was given whatsoever. Why?
...
> You might try this variation instead:
>
> my @b;
> foreach (@a) { push @b, $_ if 7 <= $_ && $_ <= 176 }
By email, Daniel Grisinger <dgris@perrin.dimensional.com> aimed me at
another approach to this problem, which I have tested successfully for
$#a = 1_000_000. It involves dealing with items from the source array
one at a time, either destructively (by shift or pop) or by indexing --
see below.
The key is to avoid creating an explicit list from the source array
(which 'foreach' does), because that adds to the memory in use
simultaneously. I was surprised that the running times of the original
grep and this approach are comparable. Here is my Benchmark, for $#a =
400_000:
#!/usr/local/bin/perl -w
use Benchmark;
my @a;
my $i;
for ($i = 0; $i < 400_000; ++$i) { push @a, int rand 256 }
timethese (1, {
Cntrl => sub { my @b = @a },
Grep => sub { my @b = grep 7 <= $_ && $_ <= 176, @a },
Index => sub { my (@b, $i);
for ($i = 0; $i < @a; ++$i)
{ push @b, $_ if 7 <= ($_ = $a[$i]) && $_ <= 176 }
},
Shift => sub { my @b;
7 <= ($_ = shift @a) && $_ <= 176 and push @b, $_ while @a;
},
} );
Benchmark: timing 1 iterations of Cntrl, Grep, Index, Shift...
Cntrl: 14 secs ( 2.21 usr 0.17 sys = 2.38 cpu)
(warning: too few iterations for a reliable count)
Grep: 54 secs ( 7.05 usr 0.50 sys = 7.55 cpu)
(warning: too few iterations for a reliable count)
Index: 51 secs (13.74 usr 0.37 sys = 14.11 cpu)
(warning: too few iterations for a reliable count)
Shift: 87 secs ( 9.11 usr 1.88 sys = 10.99 cpu)
(warning: too few iterations for a reliable count)
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 3 Jul 1998 01:34:21 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Invalid regexp in grep
Message-Id: <EvHwD9.94z@news.boeing.com>
In article <MPG.10059329f633d6979896e2@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <MPG.10055579396f137e9896e1@nntp.hpl.hp.com> on Thu, 2 Jul
>1998 09:30:19 -0700, Larry Rosler <lr@hpl.hp.com> says...
>> In article <6ng5to$oh5$1@nnrp1.dejanews.com> on Thu, 02 Jul 1998 14:36:39
>> GMT, s_emery@my-dejanews.com <s_emery@my-dejanews.com> says...
>...
>> >
>> > ...
>...
>> You might try this variation instead:
>>
>> my @b;
>> foreach (@a) { push @b, $_ if 7 <= $_ && $_ <= 176 }
>
> ....
>The key is to avoid creating an explicit list from the source array
>(which 'foreach' does), because that adds to the memory in use
>simultaneously. I was surprised that the running times of the original
>grep and this approach are comparable. Here is my Benchmark, for $#a =
>400_000:
>
>#!/usr/local/bin/perl -w
>use Benchmark;
>
>my @a;
>my $i;
>for ($i = 0; $i < 400_000; ++$i) { push @a, int rand 256 }
>
>timethese (1, {
> Cntrl => sub { my @b = @a },
> Grep => sub { my @b = grep 7 <= $_ && $_ <= 176, @a },
> Index => sub { my (@b, $i);
> for ($i = 0; $i < @a; ++$i)
> { push @b, $_ if 7 <= ($_ = $a[$i]) && $_ <= 176 }
> },
> Shift => sub { my @b;
> 7 <= ($_ = shift @a) && $_ <= 176 and push @b, $_ while @a;
> },
>} );
>
>Benchmark: timing 1 iterations of Cntrl, Grep, Index, Shift...
> Cntrl: 14 secs ( 2.21 usr 0.17 sys = 2.38 cpu)
> (warning: too few iterations for a reliable count)
> Grep: 54 secs ( 7.05 usr 0.50 sys = 7.55 cpu)
> (warning: too few iterations for a reliable count)
> Index: 51 secs (13.74 usr 0.37 sys = 14.11 cpu)
> (warning: too few iterations for a reliable count)
> Shift: 87 secs ( 9.11 usr 1.88 sys = 10.99 cpu)
> (warning: too few iterations for a reliable count)
>
A few more interations produced some interesting results
on my Solaris:
Benchmark: timing 10 iterations of Cntrl, Grep, Index, Shift...
Cntrl: 30 secs (28.74 usr 0.84 sys = 29.58 cpu)
Grep: 139 secs (134.85 usr 2.83 sys = 137.68 cpu)
Index: 438 secs (436.43 usr 0.36 sys = 436.79 cpu)
Shift: 28 secs (27.66 usr 0.15 sys = 27.81 cpu)
--
Charles DeRykus
------------------------------
Date: Thu, 2 Jul 1998 20:35:35 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Invalid regexp in grep
Message-Id: <MPG.1005f162f21c476398970f@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <EvHwD9.94z@news.boeing.com> on Fri, 3 Jul 1998 01:34:21 GMT,
Charles DeRykus <ced@bcstec.ca.boeing.com> says...
> In article <MPG.10059329f633d6979896e2@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
...
#!/usr/local/bin/perl -w
use Benchmark;
my @a;
my $i;
for ($i = 0; $i < 400_000; ++$i) { push @a, int rand 256 }
timethese (1, {
Cntrl => sub { my @b = @a },
Grep => sub { my @b = grep 7 <= $_ && $_ <= 176, @a },
Index => sub { my (@b, $i);
for ($i = 0; $i < @a; ++$i)
{ push @b, $_ if 7 <= ($_ = $a[$i]) && $_ <= 176 }
},
Shift => sub { my @b;
7 <= ($_ = shift @a) && $_ <= 176 and push @b, $_ while @a;
},
} );
> >Benchmark: timing 1 iterations of Cntrl, Grep, Index, Shift...
> > Cntrl: 14 secs ( 2.21 usr 0.17 sys = 2.38 cpu)
> > (warning: too few iterations for a reliable count)
> > Grep: 54 secs ( 7.05 usr 0.50 sys = 7.55 cpu)
> > (warning: too few iterations for a reliable count)
> > Index: 51 secs (13.74 usr 0.37 sys = 14.11 cpu)
> > (warning: too few iterations for a reliable count)
> > Shift: 87 secs ( 9.11 usr 1.88 sys = 10.99 cpu)
> > (warning: too few iterations for a reliable count)
> >
>
> A few more interations produced some interesting results
> on my Solaris:
>
> Benchmark: timing 10 iterations of Cntrl, Grep, Index, Shift...
> Cntrl: 30 secs (28.74 usr 0.84 sys = 29.58 cpu)
> Grep: 139 secs (134.85 usr 2.83 sys = 137.68 cpu)
> Index: 438 secs (436.43 usr 0.36 sys = 436.79 cpu)
> Shift: 28 secs (27.66 usr 0.15 sys = 27.81 cpu)
You cannot run the benchmark as written with more than one iteration.
'Shift' destroys the input array, so the remaining 9 iterations do
nothing. Why it was *faster* than Cntrl is a minor mystery, though.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 03 Jul 1998 03:50:23 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Invalid regexp in grep
Message-Id: <6nhjrc$hg9$1@rand.dimensional.com>
[posted and mailed to the cited author]
In article <EvHwD9.94z@news.boeing.com>
ced@bcstec.ca.boeing.com (Charles DeRykus) wrote:
<snip>
>A few more interations produced some interesting results
>on my Solaris:
>
>Benchmark: timing 10 iterations of Cntrl, Grep, Index, Shift...
> Cntrl: 30 secs (28.74 usr 0.84 sys = 29.58 cpu)
> Grep: 139 secs (134.85 usr 2.83 sys = 137.68 cpu)
> Index: 438 secs (436.43 usr 0.36 sys = 436.79 cpu)
> Shift: 28 secs (27.66 usr 0.15 sys = 27.81 cpu)
This is because the first time through the shift code clears
the array. The next nine iterations are over an empty list.
>Charles DeRykus
Daniel
--
Daniel Grisinger dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
Dave Clark
------------------------------
Date: Fri, 03 Jul 1998 04:07:17 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Invalid regexp in grep
Message-Id: <6nhkt2$hi7$1@rand.dimensional.com>
[posted and mailed to the cited author]
In article <MPG.1005f162f21c476398970f@nntp.hpl.hp.com>
lr@hpl.hp.com (Larry Rosler) wrote:
<snip>
> Cntrl => sub { my @b = @a },
> Shift => sub { my @b;
> 7 <= ($_ = shift @a) && $_ <= 176 and push @b, $_ while @a;
> },
<snip>
>You cannot run the benchmark as written with more than one iteration.
>'Shift' destroys the input array, so the remaining 9 iterations do
>nothing. Why it was *faster* than Cntrl is a minor mystery, though.
Cntrl copies @a to @b each time through. Shift destroys @a on its first
pass, leaving the while condition false for the next 9 iterations. I'd
expect evaluating C<while(@a)> when @a is an empty list to be match faster
than copying a 400000 element array :-).
>Larry Rosler
Daniel
--
Daniel Grisinger dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
Dave Clark
------------------------------
Date: Fri, 03 Jul 1998 12:50:47 GMT
From: 4newsargus@mail.entrsft.com (David Rouse)
Subject: Is Perl through CGI enough for this?
Message-Id: <4newsargus-0307980851300001@192.36.36.47>
Our company (a newspaper) has been considering building a print ads
scheduling system.
The product would basically be a database where two people (possibly more)
would enter in ads scheduling information (which publication, how large of
an ad and when -- along with other info) and another person would be
generating reports (tab delimited text files as well as formatted for
printing reports). The reports would mostly show what ads are running
tomorrow, but we would like to be able to do other reports, like how many
ads and how much space has company x run this quarter.
All of the actual accounting/billing would be handled by a commercial
product running on another server, we just need something to handle the
scheduling of ads.
I had thought to run the system using Filemaker, but I've been given a Sun
server to run the system on. So I've bought O'Reilly's "Learning Perl,"
and started lurking on this group. I'm thinking now of running the system
using web browsers on the clients and perl scripts, dbm (or something) and
apache on the server.
Will that combination be enough? Is it possible to build a system that
will be robust enough to work correctly? If someone fills in a browser
form that orders a full page ad for a certain day -- and that ad doesn't
get manifested -- the company would be loosing thousands of dollars.
David Rouse
------------------------------
Date: Thu, 02 Jul 1998 17:06:31 +0100
From: Lars Thegler <lth@dannet.dk>
To: Scott Baxter <baxter@ki.com>
Subject: Re: Java and Perl together?
Message-Id: <359BB007.7EFD3E18@dannet.dk>
Scott Baxter wrote:
>
> Hello!
>
> My boss has asked me to write a perl script to scan files while another
> guy writes a Java front end for it.
You should definitely check out 'JPL' - Larry Wall's toolkit for
creating Java and Perl hybrid applications. It's featured in the 'Perl
Resource Kit':
http://www.oreilly.com/catalog/prkunix/
--
Lars Thegler mailto:lth@dannet.dk
Internet Development http://www.dannet.dk
Dan Net A/S phone: +45 45 82 16 00
Blokken 9 - DK-3460 Birkeroed - Denmark fax: +45 45 82 16 44
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3048
**************************************