[11644] in Perl-Users-Digest
Perl-Users Digest, Issue: 5244 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 28 13:03:04 1999
Date: Sun, 28 Mar 99 10:00:18 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 28 Mar 1999 Volume: 8 Number: 5244
Today's topics:
Help with easy script <ophir@saifun.com>
Re: Help with easy script (Larry Rosler)
Re: How to convert Julian date to week day?? (Hans-Georg Rist)
Re: How to redirect in new window? <bruce@reedcommunications.com>
Ibill scripts dsm_quake@my-dejanews.com
IIS4 and Perl pfridlen@rec.unicen.edu.ar
Re: Initializing an array with STDIN (newbie) (Tad McClellan)
Perl Power Tools [project status update] <tchrist@mox.perl.com>
Perl with Access DB <choic@cs.man.ac.uk>
Re: Perl with Access DB <tony@cyberscape.net>
Re: Problem about REGULAR EXPRESSION <jacklam@math.uio.no>
Re: RE to match one line of Larry's quote <555034897s@acadiau.ca>
Re: RE to match one line of Larry's quote (Tad McClellan)
Re: RE to match one line of Larry's quote (Larry Rosler)
Re: Split with + , but no %2B <uri@home.sysarch.com>
Re: system ('myproc &'); (Tad McClellan)
re: Tom's pvdb script <paladin@uvic.ca>
Very large float arrays and size problem <loulou@ltt.ntua.gr>
Re: Where to start with Perl (Tad McClellan)
Re: why doesn't this work? (Sam Holden)
Re: why doesn't this work? <debot@xs4all.nl>
Re: why doesn't this work? (Bob Trieger)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 28 Mar 1999 16:24:19 +0200
From: Ophir Marko <ophir@saifun.com>
Subject: Help with easy script
Message-Id: <36FE3B93.30F93A63@saifun.com>
Does anyone have a script that opens a text file, searches it for a line
in which the string 'x' appears, then copy's the whole line in which the
string appeared to a new file? I'm having trouble making one, and I'm
not the worlds most patient person.
Thanks a million,
Ophir Marko
------------------------------
Date: Sun, 28 Mar 1999 09:00:12 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help with easy script
Message-Id: <MPG.1167fff0f62d83999897e2@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <36FE3B93.30F93A63@saifun.com> on Sun, 28 Mar 1999 16:24:19
+0200, Ophir Marko <ophir@saifun.com >says...
> Does anyone have a script that opens a text file, searches it for a line
> in which the string 'x' appears, then copy's the whole line in which the
> string appeared to a new file? I'm having trouble making one, and I'm
> not the worlds most patient person.
Usenet rewards patience. Your Perl documentation is closer at hand.
However...
print grep /x/, $_ while <>;
That should be short enough for even the most impatient person. I have
left out the details of file handling or how to do this as a one-liner
from the command line. I hope working them out doesn't try your
patience.
Of course, if you're really impatient and have POSIX commands available,
use this command instead of using Perl:
grep x infile >outfile
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 28 Mar 1999 17:36:46 GMT
From: hans-georg@rist.net (Hans-Georg Rist)
Subject: Re: How to convert Julian date to week day??
Message-Id: <36fe620e.1664429@news.uni-ulm.de>
hk1973@my-dejanews.com wrote:
>How do I tell which day (Mon - Sun) from a julian date. I have got some perl
>script converting date but not to week day (Mon - Sun), can anyone post the
>script or tell me the formula about it.
I used the following code to convert a Julian date to a Gregorian
date, calculated the number of the day in the year and then finally
got the week day.
HTH,
HG
#!/usr/local/bin/perl -w
use strict;
my $j = 2_451_266; # Julian day
my( $year, $month, $day ) = &g_date( $j ); # Gregorian date
my $n = &number_of_day( $year, $month, $day ); # day in year
my $w = &week_day( $year, $n ); # 0=So, 6=Sa
print "Julian date: $j\n";
printf "Gregorian date: %04d-%02d-%02d\n", $year, $month, $day;
print "weekday: ",
( "So", "Mo", "Tu", "We", "Th", "Fr", "Sa" )[$w], "\n";
exit;
#=============================================================================
sub week_day {
#-----------------------------------------------------------------------------
# Arguments: year, number of day in year
# (1=1.1., 2=2.1., ..., 365/366=31.12.)
# Returns: weekday (0=So, 1=Mo, ..., 6=Sa)
#-----------------------------------------------------------------------------
my( $year, $n ) = @_;
my( $j, $c );
$j = ( $year - 1 ) % 100;
$c = int( ( $year - 1 ) / 100 );
return ( 28 + $j + $n + int( $j / 4 ) + int( $c / 4 ) + 5 * $c ) % 7;
} # end sub week_day()
#=============================================================================
#=============================================================================
sub g_date {
#-----------------------------------------------------------------------------
# Arguments: Julian date (days since 1.1.4713 B.C.)
# Returns: year, month (1=Jan, 2=Feb, ... 12=Dec), day (1...31)
#-----------------------------------------------------------------------------
# Modified algorithm from R. G. Tantzen
#-----------------------------------------------------------------------------
my( $jd ) = @_;
my( $year, $month, $day );
$jd -= 1721119;
$year = int( ( 4 * $jd - 1 ) / 146097 );
$jd = ( 4 * $jd - 1 ) % 146097;
$day = int( $jd / 4 );
$jd = int( ( 4 * $day + 3 ) / 1461 );
$day = ( 4 * $day + 3 ) % 1461;
$day = int( ( $day + 4 ) / 4 );
$month = int( ( 5 * $day - 3 ) / 153 );
$day = ( 5 * $day - 3 ) % 153;
$day = int( ( $day + 5 ) / 5 );
$year = 100 * $year + $jd;
if ( $month < 10 ) {
$month+=3;
}
else {
$month -= 9;
$year++;
}
return ( $year, $month, $day );
} # end sub g_date()
#=============================================================================
#=============================================================================
sub number_of_day {
#-----------------------------------------------------------------------------
# Arguments: year, month (1-12), day (1-31)
# Returns: number of day in year relative to beginning of year
# (1 = 1.1., 2 = 2.1., ... 365/366 = 31.12.)
#-----------------------------------------------------------------------------
# Algorithm: Robertson
#-----------------------------------------------------------------------------
my( $year, $month, $day ) = @_;
my( $d, $e );
$d = int( ( $month + 10 ) / 13 );
$e = $day + int( ( 611 * ( $month + 2 )) / 20 ) - 2 * $d - 91;
return $e + &leapyear( $year ) * $d;
} # end sub number_of_day()
#=============================================================================
#=============================================================================
sub leapyear {
#-----------------------------------------------------------------------------
# Arguments: year
# Returns: boolean (1=true/0=false)
#-----------------------------------------------------------------------------
( $_[0] % 4 == 0 && $_[0] % 100 != 0 || $_[0] % 400 == 0 ) ? 1 : 0;
} # end sub leapyear()
#=============================================================================
--
Hans-Georg Rist
hans-georg@rist.net
------------------------------
Date: Sun, 28 Mar 1999 09:56:25 -0500
From: bruce <bruce@reedcommunications.com>
To: Michael Cameron <Michael.Cameron@REMOVETHIS.technologist.com>
Subject: Re: How to redirect in new window?
Message-Id: <36FE4317.4F031076@reedcommunications.com>
--------------C8AEB0F11701564A7F00F671
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I think the question that should have been asked was, "How do I get my Perl
script to redirect a visitor to a new browser window instead of the active
window?". I would like to know to do that also.
For example, those free homepages hosts (tripod.com, angelfire.com and
geocities.com, among others) produce annoying little advertisement windows with
their scripts.
Bruce Reed
Michael Cameron wrote:
> Tracey Bobek wrote:
>
> > I know how to create a list box the redirects the user to another website
> > within the same browser window. How do you redirect the user to another
> > website in a new window? (Like the "TARGET=_blank" tag in HTML?)
> >
> > I think the answer is simple, but I'm having trouble.
> >
> > Thanks for the help,
> >
> > Chris
>
> And I expect that simple answer is found on one of the relevant newsgroups.
> But I suspect not this one...
--------------C8AEB0F11701564A7F00F671
Content-Type: multipart/related; boundary="------------9E58EF89D1F55A9754B8FE36"
--------------9E58EF89D1F55A9754B8FE36
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
<BODY BACKGROUND="cid:part1.36FE4317.596C7582@reedcommunications.com">
I think the question that should have been asked was, "How do I get my
Perl script to redirect a visitor to a new browser window instead of the
active window?". I would like to know to do that also.
<BR>For example, those free homepages hosts (<A HREF="http://www.tripod.com">tripod.com</A>,
<A HREF="http://www.angelfire.com">angelfire.com</A> and <A HREF="http://www.geocities.com/">geocities.com</A>,
among others) produce annoying little advertisement windows with their
scripts.
<P>Bruce Reed
<P>Michael Cameron wrote:
<BLOCKQUOTE TYPE=CITE>Tracey Bobek wrote:
<P>> I know how to create a list box the redirects the user to another
website
<BR>> within the same browser window. How do you redirect the user
to another
<BR>> website in a new window? (Like the "TARGET=_blank" tag in HTML?)
<BR>>
<BR>> I think the answer is simple, but I'm having trouble.
<BR>>
<BR>> Thanks for the help,
<BR>>
<BR>> Chris
<P>And I expect that simple answer is found on one of the relevant newsgroups.
<BR>But I suspect not this one...</BLOCKQUOTE>
</BODY>
</HTML>
--------------9E58EF89D1F55A9754B8FE36
Content-Type: text/html; charset=iso-8859-1
Content-ID: <part1.36FE4317.596C7582@reedcommunications.com>
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="C:\WINDOWS\TEMP\nsmailES.html"
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9JRVRGLy9EVEQgSFRNTCAyLjAvL0VOIj4KPEhU
TUw+PEhFQUQ+CjxUSVRMRT40MDQgTm90IEZvdW5kPC9USVRMRT4KPC9IRUFEPjxCT0RZPgo8
SDE+Tm90IEZvdW5kPC9IMT4KVGhlIHJlcXVlc3RlZCBVUkwgL2Jpbi9zbWlseTIuanBlZyB3
YXMgbm90IGZvdW5kIG9uIHRoaXMgc2VydmVyLjxQPgo8L0JPRFk+PC9IVE1MPgo=
--------------9E58EF89D1F55A9754B8FE36--
--------------C8AEB0F11701564A7F00F671--
------------------------------
Date: Sun, 28 Mar 1999 15:28:44 GMT
From: dsm_quake@my-dejanews.com
Subject: Ibill scripts
Message-Id: <7dlhr7$4pk$1@nnrp1.dejanews.com>
Hi !
I need URGENTLY a script to manage Ibill's username/password lists.
I saw the resource center but the demos are limited, and I'm finding a script
to:
- Add the list (with username/password pair data delimited by ",") to
.htpasswd - Count used and remain - Allow to disable an account - If
possible, allow to include a "database" of expirations, to automatically
delete from .htpasswd users no longer valid. - Allow to "massive deletion" of
expired users from a txt based file (maybe like the one received from Ibill).
I don't see demos about this, and I can't buy any script if I cannot test it
in my real work.
THANKS FOR YOUR HELP !!!!
Daniel......
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sun, 28 Mar 1999 14:34:49 GMT
From: pfridlen@rec.unicen.edu.ar
Subject: IIS4 and Perl
Message-Id: <7dlem9$2g0$1@nnrp1.dejanews.com>
Hi,
I have IIS4 on an NT 4.00 server. There I have created a directory
"perl-scripts" as a "scripts" subdirectory, where I4ve added a simple perl
script. Then in the IIS4 manager console I have set the directory to allow
SCRIPTS,and I have configured extension "pl" to call perl.exe as script
engine. When I try visiting the script with the web browser (accessing
http://localhost/scripts/perl-scripts/prueba.pl) I can see with the NT
taskbar process browser that PERL.EXE is launched, but it has 0 resources and
00:00 cpu time, and it never appears a response in the web browser, not even
an error message. I neither can terminate the process. So the script runs ok
using DOS console, but I can4t make the script run via web, even when it4s
clear that the perl.exe application is called by the IIS when accessing the
page.
Just in case it4s useful the script is:
#!c:\perl5\bin\perl.exe
# prueba.pl
#
print "Content-type: text/html\n\n";
print "<html>", "\n";
print "<head>", "\n";
print "<title>Hola</title>", "\n";
print "</head>", "\n";
print "<body>", "\n";
print "</body>", "\n";
print "</html>", "\n";
exit;
#end prueba.pl
Thanks for your help.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sun, 28 Mar 1999 06:08:12 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Initializing an array with STDIN (newbie)
Message-Id: <si2ld7.sf4.ln@magna.metronet.com>
Sender (fairfiel@dundee.net) wrote:
: I've been trying to place an input file into an array,
You have code below that does that, so this is not a problem.
: and then split()
: that array.
You can't split() an array.
Perl's functions are described in the perlfunc.pod standard
doc. For split it says:
-----------------
=item split /PATTERN/,EXPR,LIMIT
=item split /PATTERN/,EXPR
=item split /PATTERN/
=item split
Splits a string into an array of strings, and returns it.
-----------------
So nobody knows how to do what you asked for, because
it cannot be done.
Perhaps you wanted to ask something else?
Like "split() each element of an array" ???
: I get messages indicating that the array is not initialized:
: "Use of implicit split to @_ is deprecated,"
Somewhere you are split()ing, but not storing its results
anywhere (so perl saves them for you and warns about it)
Where we cannot say, because you haven't shown any code.
: and "Use of uninitialized
: value at line xxx, <INFILE> chunk xxx."
The messages that perl might issue are described in the
'perldiag.pod' standard Perl doc. You should always look
there for messages that you recieve.
: I've tried a few approaches:
: 1. Use a loop to read each line from the text file into the array. Use
: the split() function after each line is read in, or after the whole
: array has been (supposedly) filled.
Where's that code?
: 2. Put the data file directly into the array:
: @order = <INFILE>; (With variations in syntax).
Nothing wrong with that code.
: New guy
You usually need to show code if you want the code fixed...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Mar 1999 09:48:18 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Perl Power Tools [project status update]
Message-Id: <7dlpkh$4ft$1@nntp.Stanford.EDU>
The Unix Reconstruction Project <URL: http://language.perl.com/ppt/ >
is pleased to report that we now have at least initial stabs at most
of the standard Unix tools:
addbib apply asa ar arch awk basename bc cal cat chmod chgrp chown
clear cmp colrm comm cp cut dc diff dirname dos2unix du echo egrep env
expand expr false fgrep file fold grep glob head id join kill ln look
ls make makewhatis man mimedecode mkdir mkfifo mv od paste ping pr
printenv printf pwd rev rm rmdir shar sleep sort split strings sum
tac tail tar tee test touch tr true tsort tty uname unexpand uniq
units unix2dos unshar uuencode uudecode wc what which whois xargs yes
We even have a few vintage "games":
arithmetic banner ching factor fish hangman
maze moo morse pig pom ppt primes random wump
If anyone is interested in pitching in, here's the current TODO list:
* The unimplemented tools should =~ s/^un//
* Some of what we have could use some polish (e.g. shar, unshar).
* Extensive portability testing to alien environments is
DESPERATELY needed.
* An integrated packaging and installation mechanism needs to
be devised.
* Functionality test suites to verify correctness should be
written.
Feel free to work on any or all of these. :-) Probably the easiest for
the faint of heart would be simply to download the tree and try to run
some of the tools.
--tom
--
"One planet is all you get."
------------------------------
Date: Mon, 29 Mar 1999 00:24:20 +0800
From: Mark Choi <choic@cs.man.ac.uk>
Subject: Perl with Access DB
Message-Id: <36FE57B4.DCDADCD4@cs.man.ac.uk>
Hi mates
Do you know how to retrieve data from an Access DB using Perl? Anyone
got a script about it??
Thank for for your time.
Mark
------------------------------
Date: Sun, 28 Mar 1999 18:39:09 +0100
From: "Tony Kenny" <tony@cyberscape.net>
Subject: Re: Perl with Access DB
Message-Id: <922642442.22296.0.nnrp-08.c2de1237@news.demon.co.uk>
Grab the Win32 ODBC module, the documentation is very good.
Tony
------------------------------
Date: Sun, 28 Mar 1999 13:11:43 +0200
From: Peter John Acklam <jacklam@math.uio.no>
Subject: Re: Problem about REGULAR EXPRESSION
Message-Id: <36FE0E6F.631CE451@math.uio.no>
Steve Linberg wrote:
>
> Ryan Ngi wrote:
>
> > There is $sentence= "aaabbbcccaaakkkdddeeeaaa";
> >
> > I want to pull "bbbccc" out of the sentence.
> > i use $sentence=~m/aaa(\S*)aaa/;
>
> Here's one, not the best, but should give you a pointer about what
> to look at in the documentation:
>
> $sentence = "aaabbbcccaaakkkdddeeeaaa";
> $sentence =~ m/aaa(\S*?)aaa/;
> print $1;
TIMTOWTDI:
$sentence = "aaabbbcccaaakkkdddeeeaaa";
$sentence =~ /aaa([^a]*)aaa/;
print $1, "\n";
$sentence =~ /([^a]+)/;
print $1, "\n";
Peter
--
Peter J. Acklam - jacklam@math.uio.no - http://www.math.uio.no/~jacklam
------------------------------
Date: Sun, 28 Mar 1999 10:21:35 -0400
From: Tong <555034897s@acadiau.ca>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: RE to match one line of Larry's quote
Message-Id: <36FE3AEF.395D85D6@acadiau.ca>
Larry Rosler wrote:
>
> [Posted and a courtesy copy sent.]
>
> In article <36FDAAAD.229081CD@acadiau.ca> on Sun, 28 Mar 1999 00:06:05 -
> 0400, Tong <555034897s@acadiau.ca >says...
> > Tong wrote:
> > > I want to sort out all Larry's one line quote. I.e.:
> > >
> > > ====
> > > %%
> > > And don't tell me there isn't one bit of difference between null and
> > > space,
> > > because that's exactly how much difference there is. :-)
> > > -- Larry Wall in <10209@jpl-devvax.JPL.NASA.GOV>
> > > %%
> > > "And I don't like doing silly things (except on purpose)."
> > > -- Larry Wall in <1992Jul3.191825.14435@netlabs.com>
> > > %%
> ...
> > Sorry I didn't myself clear enough. I mean, can you write a RE to match
> > *one line* of Larry's quote from "%%" to " -- Larry Wall"? If not, then
> > any RE that can pick out one line of Larry's quote will do.
>
> One such regex would be:
>
> /^%%\s+(.*?)\s+-- Larry Wall/ms
>
> where the quote proper is captured in $1.
I used "*one line* of Larry's quote" in order to stress I want only
those quotes that are, *one line*. Please explain a little bit to me
because I can't find any indication from you RE to pick only one line. I
tried it, and it does pick one line quotes, but not all of them:
======
iitrc:~/temp$ perl -ne 'undef $/; print $& if /^%%\s+(.*?)\s+-- Larry
Wall/ms' << EOQ
> %%
> Besides, including <std_ice_cubes.h> is a fatal error on machines that
> don't have it yet. Bad language design, there... :-)
> -- Larry Wall in <1991Aug22.220929.6857@netlabs.com>
> %%
> Besides, it's good to force C programmers to use the toolbox occasionally. :-)
> -- Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
> %%
> Besides, REAL computers have a rename() system call. :-)
> -- Larry Wall in <7937@jpl-devvax.JPL.NASA.GOV>
> %%
> break; /* don't do magic till later */
> -- Larry Wall in stab.c from the perl source code
> %%
> But you have to allow a little for the desire to evangelize when you
> think you have good news.
> -- Larry Wall in <1992Aug26.184221.29627@netlabs.com>
> EOQ
%%
Besides, it's good to force C programmers to use the toolbox
occasionally. :-)
-- Larry Wall
iitrc:~/temp$ perl -v
This is perl, version 5.004_04 built for sun4-solaris
======
It should pick out 3 instead of 1.
Here are a sample for you to test:
======
%%
Besides, including <std_ice_cubes.h> is a fatal error on machines that
don't have it yet. Bad language design, there... :-)
-- Larry Wall in <1991Aug22.220929.6857@netlabs.com>
%%
Besides, it's good to force C programmers to use the toolbox
occasionally. :-)
-- Larry Wall in
<1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
%%
Besides, REAL computers have a rename() system call. :-)
-- Larry Wall in <7937@jpl-devvax.JPL.NASA.GOV>
%%
break; /* don't do magic till later */
-- Larry Wall in stab.c from the perl source code
%%
But you have to allow a little for the desire to evangelize when you
think you have good news.
-- Larry Wall in <1992Aug26.184221.29627@netlabs.com>
======
> But perhaps a better approach than slurping the whole file and attacking
> it with a regex would be to set $/ to "%%\n" and get the intervening
> stuff on each readline.
Yeah, that sound a good suggestion. But I have other mutil-line RE
matching problems that do not have a %%. What I really want is the
"mutil-line RE matching". Thanks
--
Anti-Spam: Remove triple 5 to reply
------------------------------
Date: Sun, 28 Mar 1999 03:42:16 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: RE to match one line of Larry's quote
Message-Id: <81qkd7.004.ln@magna.metronet.com>
Tong (555034897s@acadiau.ca) wrote:
: Tong wrote:
: > I want to sort out all Larry's one line quote. I.e.:
[snip sample data, included below in __DATA__]
: > Only the 2nd quote got print out. But I just can't find a right RE to
: > get it. If you are curious, here are all that I could think about and
: > tried. And none of them seems working.
: >
: > ====
: > perl -ne "$/ = ''; print $& if /\s*\n.*?\n\s+-- /" lwall-q.txt
[snip a *whole bunch* of attempts]
: > I really need you to shed a light on it. Thanks!
: Sorry I didn't myself clear enough. I mean, can you write a RE to match
: *one line* of Larry's quote from "%%" to " -- Larry Wall"? If not, then
: any RE that can pick out one line of Larry's quote will do.
You were on the right track with thinking about using $/,
but you seemed to have missed the obvious string to set
it to.
When $/ is the empty string, you are in "para mode", so you
get "chunks" that are separated by one or more blank lines.
You have no blank lines in your data, so you get one chunk.
You get the same effect as when $/ is undefined (slurp mode),
only it is harder to see than if you had just undef'd $/.
Setting in to the "separator" lines makes it oh so much easier:
---------------------------
#!/usr/bin/perl -w
use strict;
$/ = "%%\n";
while (<DATA>) {
chomp; # remove the %%\n
next if /^\s*$/; # skip blank records (the first one)
s/Larry Wall.*/Larry Wall/s;
print "$_\n----------------------\n";
}
__DATA__
%%
And don't tell me there isn't one bit of difference between null and space,
because that's exactly how much difference there is. :-)
-- Larry Wall in <10209@jpl-devvax.JPL.NASA.GOV>
%%
"And I don't like doing silly things (except on purpose)."
-- Larry Wall in <1992Jul3.191825.14435@netlabs.com>
---------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 28 Mar 1999 08:40:02 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: RE to match one line of Larry's quote
Message-Id: <MPG.1167fb37fa31cc4c9897e1@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <36FE3AEF.395D85D6@acadiau.ca> on Sun, 28 Mar 1999 10:21:35 -
0400, Tong <555034897s@acadiau.ca >says...
> Larry Rosler wrote:
> >
> > [Posted and a courtesy copy sent.]
And you, Tong, should have included a similar note when you sent a
courtesy copy to me. But my email response bounced, so maybe you
didn't realize it. As this is the same address, probably this
response will bounce also.
...
> > > Sorry I didn't myself clear enough. I mean, can you write a RE to match
> > > *one line* of Larry's quote from "%%" to " -- Larry Wall"? If not, then
> > > any RE that can pick out one line of Larry's quote will do.
> >
> > One such regex would be:
> >
> > /^%%\s+(.*?)\s+-- Larry Wall/ms
> >
> > where the quote proper is captured in $1.
>
> I used "*one line* of Larry's quote" in order to stress I want only
> those quotes that are, *one line*. Please explain a little bit to me
> because I can't find any indication from you RE to pick only one line. I
> tried it, and it does pick one line quotes, but not all of them:
Here is what I think you want, with explanation (tested).
#!/usr/local/bin/perl -w
use strict;
$_ = do { local $/; <DATA> }; # Slurp the file into $_.
print $1 while /^%% # The 'start-of-quote' marker
\s+ # and whitespace before the quote
( # Start capture into $1
.+ # One or more non-newline characters
\n # and a newline
) # End capture into $1
\s+ # One or more whitespace characters
--\ Larry\ Wall # up to the 'end-of-quote' marker
/gmx; # Do it as many times as possible
__END__
%%
Besides, including <std_ice_cubes.h> is a fatal error on machines that
don't have it yet. Bad language design, there... :-)
-- Larry Wall in <1991Aug22.220929.6857@netlabs.com>
%%
Besides, it's good to force C programmers to use the toolbox
occasionally. :-)
-- Larry Wall in <1991May31.181659.28817@jpl-
devvax.jpl.nasa.gov>
%%
Besides, REAL computers have a rename() system call. :-)
-- Larry Wall in <7937@jpl-devvax.JPL.NASA.GOV>
%%
break; /* don't do magic till later */
-- Larry Wall in stab.c from the perl source code
%%
But you have to allow a little for the desire to evangelize when you
think you have good news.
-- Larry Wall in <1992Aug26.184221.29627@netlabs.com>
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 28 Mar 1999 12:57:23 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Split with + , but no %2B
Message-Id: <x790chxzss.fsf@home.sysarch.com>
>>>>> "FdB" == Frank de Bot <debot@xs4all.nl> writes:
FdB> Ok, here it is:
FdB> This is the Query string: q=Free+%2BPerl+Scripts
FdB> @array = split (/\+/, $in{'q'});
FdB> The arrays are:
FdB> $array[0] = Free
FdB> $array[1] = (empty)
FdB> $array[2] = Perl
FdB> $array[3] = Scripts
FdB> But I want it to be this way:
FdB> $array[0] = Free
FdB> $array[1] = +Perl
FdB> $array[2] = Scripts
so why doesn't split( '+', $in{'q'} ) work for you? it will not see %2B
since that is not a + but a hex encoded +. so then you have to unencode
the % escapes which will get '+Perl'for you. or even better why are you
processing cgi queries by hand? use CGI.pm and save yourself tons of
work and trouble.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sun, 28 Mar 1999 05:57:52 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: system ('myproc &');
Message-Id: <gv1ld7.sf4.ln@magna.metronet.com>
sstarre@my-dejanews.com wrote:
: Subject: system ('myproc &');
^^^^^^
^^^^^^
: When started from CGI, the browser waits until the background process
: finishes. This is an expected result. Is there a way to run the process
: detached and to not have the parent wait for it to complete?
The very first sentence of the description of system()
in the perlfunc.pod tells how to do that.
You are not really using functions without reading their
descriptions, are you?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 28 Mar 1999 04:09:41 -0800
From: Draco Paladin <paladin@uvic.ca>
Subject: re: Tom's pvdb script
Message-Id: <Pine.A41.4.05.9903280406050.60598-100000@unix3.UVic.CA>
I have been playing around with Tom's pvdb script that he posted to
clp.misc a few days ago and all I can say is... wow. That's some peice of
work. Anyone that uses Xwindows (or varients there of) should check this
script out. I know it's going to make my job debugging scripts a whole
lot easier.
(For those who didn't save the message, do a search on Deja News for
'SRC: pvdb')
--
Mother is the name for GOD on the lips and
hearts of all children. - Eric Draven
------------------------------
Date: Sun, 28 Mar 1999 17:13:57 +0300
From: Costis Angelis <loulou@ltt.ntua.gr>
Subject: Very large float arrays and size problem
Message-Id: <36FE3925.11DB8127@ltt.ntua.gr>
I am facing the following situation. I want to read an ASCII file
containing float values and then write the same file in packed format.
The problem lies in that the file is relatively large. It describes a 3D
grid and result file, containing about 175,000 points (not very large).
Now, after a lot of tries (I am not a very experienced Perl programmer)
I ended up with something like the following:
$_=<STDIN>;
@temp=split;
push @x pack("f",$temp[0]);
push @y pack("f",$temp[1]);
push @z pack("f",$temp[2]);
Now the problem is that the memory requirements are just huge. For the
175,000 points and 3 coordinates per point, it ends up using about
25MB of memory. With the 9 fields of data I want to read, it eats up
120MB, bringing the system to its limits (I have 128MB RAM). Now, this
is a relatively compact problem and I use this PC just for
post-processing, but I would never imagine that it would be this bad. I
would expect something of the order of 8*(3+9)*175,000, which is roughly
16MB.
Why is so much memory used? Am I doing something way too wrong? FWIW,
I have read every documentation page I could get my hands on. I can work
around the problem, by handling each field independently, but this would
mean parsing the data file something like 10 times. Not very efficient.
Any help will be appreciated,
TIA,
Costis Angelis
----
cangelis@hpc.ntua.gr <--- preferred
loulou@ltt.ntua.gr
------------------------------
Date: Sun, 28 Mar 1999 03:44:56 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Where to start with Perl
Message-Id: <86qkd7.004.ln@magna.metronet.com>
Randal L. Schwartz (merlyn@stonehenge.com) wrote:
: >>>>> "David" == David L Cassell <cassell@mail.cor.epa.gov> writes:
: David> richb@ezl.com wrote:
: >> I learned Perl by reading the book "Learning Perl" by Randle Schwartz and
: David> s/Randle/Randal/
: And besides the other obvious alternate spelling for my first name,
: I've seen at least two more. And when you cross-product that with all
: the wonderful ways to spell my last name, the odds of anyone getting
: it right are pretty small.
Thanks for explaning that to us Bob.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Mar 1999 14:22:06 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: why doesn't this work?
Message-Id: <slrn7fseoe.s0l.sholden@pgrad.cs.usyd.edu.au>
On Sun, 28 Mar 1999 08:44:48 -0500, Aaron Walker <amwalker@gate.net> wrote:
>I have a cgi script that deletes a line from a file based no whether or
>not the line was found with a RE.
>When I use a form for the interface to the script, it tries to call the
>script, but sits there until it times out.
>If I try to run the script from the shell, I get nothing; it just sits
>there.
You could always try using the debuggern and stepping through the code,
the location of the problem will quickly be revealed...
>
>Here's the script:
>
>#!/usr/bin/perl
You forgot the -w, and the use strict...
>require("cgi-lib.pl");
Any reason you aren't using CGI.pm?
>
>&ReadParse(*input);
>$del = $input{'del'};
>
>open(FILE, "/home/httpd/cgi-bin/catalog.dat");
You forgot the || die "Couldn't open catalog.dat : $!" before the semi-colon.
>@data = <FILE>;
>close(FILE);
>
>open(TEMP, ">/home/httpd/cgi-bin/catalog.dat");
You forgot the || die "Couldn't open catalog.dat : $!" again...
Also concurrent execution is going to ruin your whole day. You need some kind
of locking scheme...
>foreach $i (@data)
>{
> while($i !~ /$del/i)
> {
> print TEMP "$i\n";
> }
What do you think would happen if there was no match with the regex.
I thnk you might find the while would loop forever.
Are you sure you didn't mean if???
Also is there any reason for you re-implementing grep...
Have a look at 'perldoc -f grep' - it'll make the task much easier, and get
rid of that infinite loop all in one go.
>}
>close(TEMP);
>
>print "Content-type: text/html\n\n";
>print "<html><body><a href=\"/cgi-bin/catalog.pl?view\">Back to
>catalog</a>";
>print "</body></html>";
HERE documents would make that much more readable.
>
>Any ideas why this doesn't work? It looks pretty straitfoward to me.
Because you have a test in a while loop which is not affected by the contents
of the loop, or the test itself and thus will get you an infinite loop if it
ever ends up being true.
--
Sam
In case you hadn't noticed, Perl is not big on originality.
--Larry Wall
------------------------------
Date: Sun, 28 Mar 1999 17:05:21 +0200
From: Frank de Bot <debot@xs4all.nl>
Subject: Re: why doesn't this work?
Message-Id: <36FE4530.175E4417@xs4all.nl>
I think you better use this code instead of the library cgi-lib.pl (It's
some easier to understand):
local ( *in ) = @_ if @_;
local ( $i, $key, $val, $in );
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
@in = split(/[&;]/,$in);
foreach $i (0 .. $#in) {
$in[$i] =~ s/\+/ /g;
($key, $val) = split(/=/,$in[$i],2);
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
# The Rest of the Code
open(FILE, "/home/httpd/cgi-bin/catalog.dat") || &error;
@data = <FILE>;
close(FILE);
open(TEMP, ">/home/httpd/cgi-bin/catalog.dat");
foreach $i (@data) {
while($i !~ /$del/i) {
print TEMP "$i\n";
}
}
close(TEMP);
print "Content-type: text/html\n\n";
print "<html><body><a href=\"/cgi-bin/catalog.pl?view\">Back to
catalog</a>";
print "</body></html>";
# Error handling
sub error {
print "content-type: text/html\n\n";
print "Error: $!";
exit;
}
(I've also add some error handling in case the location of the file isn't
right)
Aaron Walker wrote:
> I have a cgi script that deletes a line from a file based no whether or
> not the line was found with a RE.
> When I use a form for the interface to the script, it tries to call the
> script, but sits there until it times out.
> If I try to run the script from the shell, I get nothing; it just sits
> there.
>
> Here's the script:
>
> #!/usr/bin/perl
> require("cgi-lib.pl");
>
> &ReadParse(*input);
> $del = $input{'del'};
>
> open(FILE, "/home/httpd/cgi-bin/catalog.dat");
> @data = <FILE>;
> close(FILE);
>
> open(TEMP, ">/home/httpd/cgi-bin/catalog.dat");
> foreach $i (@data)
> {
> while($i !~ /$del/i)
> {
> print TEMP "$i\n";
> }
> }
> close(TEMP);
>
> print "Content-type: text/html\n\n";
> print "<html><body><a href=\"/cgi-bin/catalog.pl?view\">Back to
> catalog</a>";
> print "</body></html>";
>
> Any ideas why this doesn't work? It looks pretty straitfoward to me.
>
> Thanks,
> Aaron
------------------------------
Date: Sun, 28 Mar 1999 15:09:45 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: why doesn't this work?
Message-Id: <7dlgrh$q2n$1@fir.prod.itd.earthlink.net>
Aaron Walker <amwalker@gate.net> wrote:
>#!/usr/bin/perl
You should use the "-w" switch. It will warn you of a lot of errors before
they become headaches.
>require("cgi-lib.pl");
Use CGI.pm instead. It is backwards compatible and all of you calls to
cgi-lib.pl should work fine.
>&ReadParse(*input);
>$del = $input{'del'};
>
>open(FILE, "/home/httpd/cgi-bin/catalog.dat");
Always check the status of your filehandle opens. This is most likely where
your problem is and if you were checking you wouldn't have to ask in c.l.p.m
>@data = <FILE>;
>close(FILE);
>
>open(TEMP, ">/home/httpd/cgi-bin/catalog.dat");
Check the status from the open!
>foreach $i (@data)
>{
> while($i !~ /$del/i)
> {
> print TEMP "$i\n";
You never chomp the newline off of the original line. Are you sure you want to
add another newline?
> }
>}
>close(TEMP);
>
>print "Content-type: text/html\n\n";
>print "<html><body><a href=\"/cgi-bin/catalog.pl?view\">Back to
>catalog</a>";
>print "</body></html>";
>
>Any ideas why this doesn't work? It looks pretty straitfoward to me.
What does it say if run from the command line?
Good luck
Bob Trieger
sowmaster@juicepigs.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5244
**************************************