[11496] in Perl-Users-Digest
Perl-Users Digest, Issue: 5096 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 9 17:07:26 1999
Date: Tue, 9 Mar 99 14:00:21 -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 Tue, 9 Mar 1999 Volume: 8 Number: 5096
Today's topics:
Re: [HOW TO?] Strip all but certain characters from a s (Tad McClellan)
Re: append 3 huge log files <aqumsieh@matrox.com>
Re: constant in Perl? <zenin@bawdycaste.org>
Counter problem... HEEELLP! <flanker@sonnet.ru>
Re: Counter problem... HEEELLP! <jglascoe@giss.nasa.gov>
Re: Counter problem... HEEELLP! <staffan@ngb.se>
database search script - a modification needed <c.coughlan@ucl.ac.uk>
Days in Month array <design@raincloud-studios.com>
Re: Days in Month array <jglascoe@giss.nasa.gov>
Re: deletion problem <aqumsieh@matrox.com>
FAQ 3.15: What is undump? <perlfaq-suggestions@perl.com>
Re: Faster way to read lines from a file (was Re: Sorti <aqumsieh@matrox.com>
Re: Faster way to read lines from a file (was Re: Sorti (Fuzzy Warm Moogles)
How to check whether data is ready on a socket? <stubbs@say.wut>
just check 030999 <kli@profdev.sjsu.edu>
Re: New regex features (was Re: FAQ 4.20: How do I find (Ilya Zakharevich)
Re: Newbie needs help!! <kli@profdev.sjsu.edu>
Re: opinion please (brian d foy)
Perl and a Here document kstinson@hotmail.com
Re: Perl and a Here document <jglascoe@giss.nasa.gov>
Re: Perl format statement question scraig@my-dejanews.com
Re: Referencing arrays with contents of scalars? <jglascoe@giss.nasa.gov>
RTF=>HTML with extracted GIFs or JPEGs <flanker@sonnet.ru>
Re: Sendmail <staffan@ngb.se>
Re: Sendmail <kli@profdev.sjsu.edu>
Shouldn't we have 'perlmonger' ? <aqumsieh@matrox.com>
Re: Speed-optimizing regular expressions <complangperlmisc@NOSPAMPLEASE.httptech.com>
SSI within CGI <thespaceport@my-dejanews.com>
Re: Why isn't this a race condition ? <kli@profdev.sjsu.edu>
Re: y2k and 4-digit dates (was Re: foreach and while) <staffan@ngb.se>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 9 Mar 1999 09:23:46 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: [HOW TO?] Strip all but certain characters from a string
Message-Id: <ita3c7.6k.ln@magna.metronet.com>
Jason Hatcher (Jason@InsideMedicine.com) wrote:
: I am looking for an efficient way to strip a string down to only certain
: characters.
: The output is 8 numbers followed by a the letter "S" or a number.
So there are 11 "certain characters" that are allowed:
0-9 and S?
Strip everything except those 11 chars:
s/[^\dS]+//g;
or do the same thing only faster:
tr/0-9S//cd;
Now see if it matches your description above:
print "bad $_\n" unless /^\d{8}[\dS]$/;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 09 Mar 1999 20:07:44 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: append 3 huge log files
Message-Id: <7c3v28$v64$1@nnrp1.dejanews.com>
In article <7bt6tq$a5b$1@nnrp1.dejanews.com>,
vnguyen2891@my-dejanews.com wrote:
> I got 3 huge log files which I want to append them all into one file ( put 3
> files into 1 file). Do you have any suggestion to do it? Please give me
> detailed suggestion.
This is as detailed as it gets:
perl -pe "" file1 file2 file3 > logfile
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 09 Mar 1999 19:01:39 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: constant in Perl?
Message-Id: <921006352.341352@thrush.omix.com>
Mark-Jason Dominus <mjd@op.net> wrote:
>snip<
: Where `myconstants.pm' contains:
: # Note that there is NO PACKAGE DECLARATION HERE.
: sub PI () { 3 }
: sub NUMBER_OF_NOSTRILS () { 2 }
: sub fine_structure () { 7.29735308e-3 }
: 1;
: That works perfectly well, and you don't need the exporter at all.
: (Potential disadvantage: Only one package can `use myconstants'; if
: you do a subsequent `use myconstants' in a different package in the
: same program, it is ineffective. To avoid this, you need to use the
: exporter, or do the exportation yourself.)
package Foo;
BEGIN { do "myconstants.pl" }
package Bar;
BEGIN { do "myconstants.pl" }
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Tue, 9 Mar 1999 22:27:41 +0300
From: "Michael Yevdokimov" <flanker@sonnet.ru>
Subject: Counter problem... HEEELLP!
Message-Id: <7c3skb$bpm$1@bison.rosnet.ru>
HELLO!
I want to create a small image counter. I've already written some code
for it (see below). I have a problem with showing numbers' images.. I
understand that my FOR..LOOP construction overwrites the previous
output image...
$base1="../../count/imgs";
$base2="../../count";
%imgs=(
"0", "0.gif",
"1", "1.gif",
"2", "2.gif",
"3", "3.gif",
"4", "4.gif",
"5", "5.gif",
"6", "6.gif",
"7", "7.gif",
"8", "8.gif",
"9", "9.gif"
);
open (F1,"<$base2/temp.txt");
$cont=<F1>;
close(F1);
#For example our temp.txt has number 10000 inside
$sl=length($cont);
binmode(STDOUT);
print "Content-type:image/gif\n\n";
for ($i=0;$i<$sl;$i++) {
$n=substr($cont,$i,1);
open (IMG, "$base1/$imgs{$n}");
binmode(IMG);
print STDOUT <IMG>;
close(IMG);
}
Can anyone consult me how to make a normal sequence of images, i.e.
how to correct program's bug? ;-)
Thanks in advance!
--
Best wishes,
Michael Yevdokimov
Email: flanker@sonnet.ru
ICQ: 30874618
-------------------------------------------------
>> Developers Support Site <<
Web: http://developer.tsx.org
http://www.basicnet.sonnet.ru
-------------------------------------------------
------------------------------
Date: Tue, 09 Mar 1999 14:59:46 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Michael Yevdokimov <flanker@sonnet.ru>
Subject: Re: Counter problem... HEEELLP!
Message-Id: <36E57DB2.20A1696F@giss.nasa.gov>
[posted and mailed]
Michael Yevdokimov wrote:
>
> I want to create a small image counter. I've already written some code
> for it (see below). I have a problem with showing numbers' images.. I
> understand that my FOR..LOOP construction overwrites the previous
> output image...
Yes, your program should spit out HTML with the
images embedded in it.
> $base1="../../count/imgs";
> $base2="../../count";
> %imgs=(
> "0", "0.gif",
> "1", "1.gif",
[... snip ...]
> "9", "9.gif"
> );
my @images = ();
$images[$_] = "$_.gif" foreach (0..9);
> open (F1,"<$base2/temp.txt");
open F1, "< bleah" or die "biz: $!";
> $cont=<F1>;
chomp(my $count = <F1>); # like an extra "u" would kill you ;^)
> close(F1);
>
> #For example our temp.txt has number 10000 inside
>
> $sl=length($cont);
> binmode(STDOUT);
>
> print "Content-type:image/gif\n\n";
> for ($i=0;$i<$sl;$i++) {
> $n=substr($cont,$i,1);
> open (IMG, "$base1/$imgs{$n}");
> binmode(IMG);
> print STDOUT <IMG>;
> close(IMG);
> }
# here's a very basic web page:
print "Content-type: text/html\n\n";
foreach my $n (split '', $count) {
print qq {
<img src="$base1/$images[$n]">
};
}
> Can anyone consult me how to make a normal sequence of images, i.e.
> how to correct program's bug? ;-)
let the browser access the gif files itself.
It was designed to do that.
Jay Glascoe
--
"Narf!"
--Pinky
------------------------------
Date: Tue, 09 Mar 1999 22:22:10 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Counter problem... HEEELLP!
Message-Id: <36E59102.7B3AE3BD@ngb.se>
Michael Yevdokimov wrote:
>
> HELLO!
>
> I want to create a small image counter. I've already written some code
> for it (see below). I have a problem with showing numbers' images.. I
> understand that my FOR..LOOP construction overwrites the previous
> output image...
You should look into GD.pm, I don't think you can do the pasting of GIFs
yourself... (You can, but it's hard... I've tried :-( ) Look at:
http://theory.uwinnipeg.ca/CPAN/data/GD/GD.html
HTH
Staffan
------------------------------
Date: Tue, 09 Mar 1999 21:09:33 GMT
From: "cathal coughlan" <c.coughlan@ucl.ac.uk>
Subject: database search script - a modification needed
Message-Id: <01be6a70$44fd87a0$9cc666c3@e-base.u-net.com>
Hi,
I wonder if anyone could find the time to help me out with this script. It
presently searches a formatted textfile database quite happily, one field
at a time.
I need it to accept values of TWO variables from a HTML form, though, and
carry out a joined search (a Boolean AND, in effect), returning the records
which meet both criteria.
Here's the script:
#!/bin/perl
# requires cgi-lib.pl
require "cgi-lib.pl";
# grab values passed from form:
&ReadParse(*in);
print "Content-type: text/html\n\n";
# print the top part of the response
print "<HTML><HEAD><TITLE>Organisations Search Results</TITLE></HEAD>\n";
print "<body bgcolor=\"#FFFFFF\" text=\"maroon\" link=\"#990000\"
vlink=\"#666666\" alink=\"#CC9900\"><CENTER><h3><font face=\"verdana,
arial, helvetica\" color=\"maroon\">";
#Tower Hamlets Agenda 21 Community Network</FONT></h3></CENTER>\n";
print "<center><img src=\"images/a21_hd.jpg\">\n";
print "<center><font face=\"verdana, arial, helvetica\"><H5>The
organisations or individuals whose details most closely fit your search
criteria are as follows:</H5>\n";
print "<table><tr><td><center><font face=\"verdana, arial, helvetica\"
SIZE=-1>\n";
# read and parse data file
$data="director.dat";
open(DATA,"$data") || die "Can't open $data: $!\n</BODY></HTML>\n";
while(<DATA>) {
chop; # delete trailing \n
if (/^\s*$/) {
# break between records
if ($match) {
# if anything matched, print the whole record
&printrecord($record);
$nrecords_matched++;
}
undef $match;
undef $record;
next;
}
# tag: value
($tag,$val) = split(/:/,$_,2);
if ($tag =~ /^First Name/i) {
$match++ if( $in{'First Name'} && $val =~ /\b$in{'First Name'}/i) ;
$record ="<B>$val</B>";
next;
}
if ($tag =~ /^Last Name/i) {
$match++ if( $in{'Last Name'} && $val =~ /\b$in{'Last Name'}\b/i) ;
$record .= "<B>$val</B>";
next;
}
if ($tag =~ /^Organisation/i) {
$match++ if( $in{'Organisation'} && $val =~ /\b$in{'Organisation'}\b/i) ;
$record .= "\n<br><B>$val</B>" if ($val);
next;
}
if ($tag =~ /^Address/i) {
$match++ if( $in{'Address'} && $val =~ /\b$in{'Address'}\b/i) ;
$record .= "\n<BR>$val" if ($val);
next;
}
if ($tag =~ /^District/i) {
$match++ if( $in{'District'} && $val =~ /\b$in{'District'}\b/i) ;
$record .= "\n<br> $val" if ($val ne " ");
next;
}
if ($tag =~ /^Postcode/i) {
$match++ if( $in{'Postcode'} && $val =~ /\b$in{'Postcode'}\b/i) ;
$record .= "\n<BR>London $val" if ($val ne " ");
next;
}
if ($tag =~ /^Work Tel/i) {
$match++ if( $in{'Work Tel'} && $val =~ /\b$in{'Work Tel'}\b/i) ;
$record .= "\n<BR><b>Daytime Telephone:</b> $val" if ($val ne " ");
next;
}
if ($tag =~ /^Work Ext/i) {
$match++ if( $in{'Work Ext'} && $val =~ /\b$in{'Work Ext'}\b/i) ;
$record .= " <b>Extension:</b> $val" if ($val ne " ");
next;
}
if ($tag =~ /^Home Telephone/i) {
$match++ if( $in{'Home Telephone'} && $val =~ /\b$in{'Home
Telephone'}\b/i) ;
$record .= "\n<BR><b>Home Telephone:</b> $val" if ($val ne " ");
next;
}
if ($tag =~ /^Map/i) {
$match++ if( $in{'Map'} && $val =~ /\b$in{'Map'}\b/i) ;
$record .= "<BR><br><FONT SIZE=\"-2\"><B><A
HREF=\"http://uk.multimap.com/p/browse.cgi?pc=$val\"
TARGET=\"multimap\">Click here to see location on Multimap in a new
window</A></B></FONT>";
next;
}
#anything else
#$record .= $_;
}
close DATA;
if (! defined $nrecords_matched)
{ print "<H3>Sorry, there are no records matching your enquiry</H3>\n"; }
else {
print "<p>$nrecords_matched records matched<HR NOSHADE>"; }
#print "<p align=\"center\"><img src=\"images/blesepa.gif\"></p>\n";
print "<a href=\"index.html\"><h3>Search again</a></p></h3>\n";
print "<a href=\"add.html\"><h3>Add a name to the database</a></p></h3>\n";
print "</td></tr></table></center></BODY></HTML>\n";
exit;
sub printrecord {
local($buf) = @_;
print "<HR>\n$buf\n";
}
Thanks for reading this.
Cathal Coughlan (c.coughlan@ucl.ac.uk)
------------------------------
Date: Tue, 09 Mar 1999 21:06:14 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Days in Month array
Message-Id: <a3gF2.224$0l4.330@news.rdc1.tn.home.com>
I'm trying to build a timeline of days and dates when given a
year. Leap years are messin with my code.
How does one calculate if a given year is a leap year?
CT
------------------------------
Date: Tue, 09 Mar 1999 16:33:23 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Days in Month array
Message-Id: <36E593A3.1C18C693@giss.nasa.gov>
[posted and mailed]
"Charles R. Thompson" wrote:
>
> I'm trying to build a timeline of days and dates when given a
> year. Leap years are messin with my code.
>
> How does one calculate if a given year is a leap year?
>
> CT
isn't it simply
print "leap year\n" if $year % 4 == 0;
Jay Glascoe
--
"The number of UNIX installations has grown to 10, with more expected."
-- _The UNIX Programmer's Manual_, Second Edition, June, 1972.
------------------------------
Date: Tue, 09 Mar 1999 20:54:43 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: deletion problem
Message-Id: <7c41qd$1th$1@nnrp1.dejanews.com>
In article <comdog-ya02408000R0703992005510001@news.panix.com>,
comdog@computerdog.com (brian d foy) wrote:
> In article <7bsgtj$p9t$1@nnrp1.dejanews.com>, @l@ <aqumsieh@matrox.com>
posted:
>
> > --Ala
> > $monger->{montreal}->[0];
>
> why are you signing your posts with Nicolas Bertrand's
> monger designation?
I like it ..
is it copyrighted? any problems with that?
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 9 Mar 1999 13:15:18 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 3.15: What is undump?
Message-Id: <36e58156@csnews>
(This excerpt from perlfaq3 - Programming Tools
($Revision: 1.33 $, $Date: 1998/12/29 20:12:12 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq3.html
if your negligent system adminstrator has been remiss in his duties.)
What is undump?
See the next questions.
--
If I had only known, I would have been a locksmith. --Albert Einstein
------------------------------
Date: Tue, 09 Mar 1999 20:28:13 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Faster way to read lines from a file (was Re: Sorting trouble. Almost solved. Final touch needed.)
Message-Id: <7c408g$ba$1@nnrp1.dejanews.com>
In article <36e318eb.326191328@news.oz.net>,
tgy@chocobo.org wrote:
> Faster? Not by a long shot. Anyone remember the Python thread awhile
> back, where a Python snippet slurped in file lines faster than Perl?
> <> has to copy stuff twice. split() has optimized this slowdown away.
>
> Below are some benchmarks. Note the huge difference between 'Array'
> (your solution + chomp) and 'Split' (Par's solution without the costly
> line-by-line buildup of $wholefile):
>
> Benchmark: timing 100 iterations of Aqum, Array, Par, RE, Split...
> Aqum: 16 wallclock secs (16.09 usr + 0.00 sys = 16.09 CPU)
> Array: 17 wallclock secs (17.74 usr + 0.00 sys = 17.74 CPU)
> Par: 17 wallclock secs (16.04 usr + 0.00 sys = 16.04 CPU)
> RE: 12 wallclock secs (12.74 usr + 0.00 sys = 12.74 CPU)
> Split: 10 wallclock secs (10.22 usr + 0.00 sys = 10.22 CPU)
and here are MY benchmarks .. using the exact same program you posted:
Benchmark: timing 100 iterations of Aqum, Array, Par, RE, Split...
Aqum: 27 secs (20.93 usr 0.24 sys = 21.17 cpu)
Array: 31 secs (23.15 usr 0.32 sys = 23.47 cpu)
Par: 59 secs (40.12 usr 0.23 sys = 40.35 cpu)
RE: 35 secs (23.09 usr 0.25 sys = 23.34 cpu)
Split: 32 secs (20.26 usr 0.21 sys = 20.47 cpu)
I actually did benchmark, just in case I had to back up my claim. And I got
results very similar to these, which show that my solution is at least twice
faster than his. There is also virtually no difference between 'Array' and
'Split', contrary to what your benchmarks say.
But, this brings up another issue. Is Benchmark.pm really that reliable?
I ran the EXACT SAME program you posted.
btw:
% perl -v
This is perl, version 5.004_04 built for sun4-solaris
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 09 Mar 1999 21:47:43 GMT
From: tgy@chocobo.org (Fuzzy Warm Moogles)
Subject: Re: Faster way to read lines from a file (was Re: Sorting trouble. Almost solved. Final touch needed.)
Message-Id: <36e591d3.553785708@news.oz.net>
On Tue, 09 Mar 1999 20:28:13 GMT, @l@ <aqumsieh@matrox.com> wrote:
>In article <36e318eb.326191328@news.oz.net>,
> tgy@chocobo.org wrote:
>
>> Faster? Not by a long shot. Anyone remember the Python thread awhile
>> back, where a Python snippet slurped in file lines faster than Perl?
>> <> has to copy stuff twice. split() has optimized this slowdown away.
>>
>> Below are some benchmarks. Note the huge difference between 'Array'
>> (your solution + chomp) and 'Split' (Par's solution without the costly
>> line-by-line buildup of $wholefile):
>>
>> Benchmark: timing 100 iterations of Aqum, Array, Par, RE, Split...
>> Aqum: 16 wallclock secs (16.09 usr + 0.00 sys = 16.09 CPU)
>> Array: 17 wallclock secs (17.74 usr + 0.00 sys = 17.74 CPU)
>> Par: 17 wallclock secs (16.04 usr + 0.00 sys = 16.04 CPU)
>> RE: 12 wallclock secs (12.74 usr + 0.00 sys = 12.74 CPU)
>> Split: 10 wallclock secs (10.22 usr + 0.00 sys = 10.22 CPU)
>
>and here are MY benchmarks .. using the exact same program you posted:
>
>Benchmark: timing 100 iterations of Aqum, Array, Par, RE, Split...
> Aqum: 27 secs (20.93 usr 0.24 sys = 21.17 cpu)
> Array: 31 secs (23.15 usr 0.32 sys = 23.47 cpu)
> Par: 59 secs (40.12 usr 0.23 sys = 40.35 cpu)
> RE: 35 secs (23.09 usr 0.25 sys = 23.34 cpu)
> Split: 32 secs (20.26 usr 0.21 sys = 20.47 cpu)
>
>I actually did benchmark, just in case I had to back up my claim. And I got
>results very similar to these, which show that my solution is at least twice
>faster than his. There is also virtually no difference between 'Array' and
>'Split', contrary to what your benchmarks say.
>
>But, this brings up another issue. Is Benchmark.pm really that reliable?
>I ran the EXACT SAME program you posted.
Benchmark.pm isn't the culprit here....
>btw:
>
>% perl -v
>
>This is perl, version 5.004_04 built for sun4-solaris
Apologies for not including version info with mine:
C:\moogle>perl -v
This is perl, version 5.005_02 built for MSWin32-x86-object
The optimization to split() is in the newer perls. 5.006 will probably
optimize <> a bit also, so the speed difference is only temporary. I was in
no way advocating that Par's solution was better than yours and wouldn't use
it myself. I just found it interesting and counter-intuitive that the
idiomatic approach was slower... at least on my perl :)
--
perl -e '1 while print "I want a moogle stuffy!\n"'
------------------------------
Date: Tue, 09 Mar 1999 14:01:08 -0500
From: Thurgood Stubbs <stubbs@say.wut>
Subject: How to check whether data is ready on a socket?
Message-Id: <36E56FF4.CB3D04A2@say.wut>
I'm a Perl newbie on Solaris 5.5.1, trying to do some socket I/O. I
need to be able to query whtehr there's some input available on a given
socket, without blocking. Is there a way to do this?
Thanks in advance.
------------------------------
Date: Tue, 09 Mar 1999 11:24:11 -0800
From: Ken Li <kli@profdev.sjsu.edu>
Subject: just check 030999
Message-Id: <36E5755B.EDB07BBC@profdev.sjsu.edu>
------------------------------
Date: 9 Mar 1999 21:07:24 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: New regex features (was Re: FAQ 4.20: How do I find matching/nesting anything?)
Message-Id: <7c42ic$13$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Daniel Grisinger
<dgris@moiraine.dimensional.com>],
who wrote in article <m33e3e4i0m.fsf@moiraine.dimensional.com>:
> > The syntax has not been simplified yet to the simplest possible one,
> > either with (?p $postponed ), or with //p.
> Ok, question time. I apparently have misunderstood how this
> shoudl work.
>
> I have this-
> my $regex; # declare, don't initialize (why?)
> my $input = <DATA>;
> $regex = qr!
> \(
> (?:
> (?: [^()]+ )
> |
> (?p{ $regex })
> )*
> \)
> !x;
> print "[$1]\n" while $input =~ /($regex)/g;
> __END__
> (this ( is (an( example ) (of ) some)) balanced) parens
>
> Running it produces-
>
> [( example )]
> [(of )]
>
> which makes no sense to me.
a) First of all, your REx is badly flawed. Effectively, you have
(?: [^()]+ )*
as a subREx, which is a nonono wrt backtracking. You need to
advice the REx engine that you do not need backtracking on the
internal + :
(?> [^()]+ )*
(In this context > means go as far right as you can, and forget
about everything else. ;-)
b) There was (is?) a long-standing bug with resolving lexicals inside
{?{}} in a REx which is compiled at runtime (like your
/($regex)/g):
perl -lwe "$a=5; my $a=3; $r=qr/(?{print $a})/; 'a'=~/a$r/"
5
I thought that one of Hugo's patched (around 5.00553 and 5.00554)
fixed it, but at least it is present in stock 5.005_54 and my
heavily patched 5.005_53. Which version of Perl did you run? One
bug which Hugo found was not fixed, but I do not remember whether
it coincides with this one.
To circumvent the bug, either remove 'my', or replace your REx
with one which is not recompiled at run time:
/$regex/g
or
/((?p{$regex}))/g
Hope this helps,
Ilya
------------------------------
Date: Tue, 09 Mar 1999 11:29:34 -0800
From: Ken Li <kli@profdev.sjsu.edu>
Subject: Re: Newbie needs help!!
Message-Id: <36E5769E.A66786EE@profdev.sjsu.edu>
just check
Dev wrote:
> I have just started using Perl and have come up against a rather annoying
> problem. I am writing a script file that will take users comments and
> place them in a text file, and give the user a dynamically created HTML
> page, thanking him/her for their input. The error I get when I compile it
> is "Missing comma after first argument to open function at comments.cgi
> line 49, near "$fname)". Here is a sample of the code:
>
> $fname = ">>", $COMMENT_FILE;
> open(OUT $fname);
>
> This was an example taken from a book, and I copied it verbatim, which is
> why this error is soooo annoying!! Can anyone help?!??!?
>
> Dev >:)<-<
------------------------------
Date: Tue, 09 Mar 1999 14:34:23 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: opinion please
Message-Id: <comdog-ya02408000R0903991434230001@news.panix.com>
In article <36E4B173.8758A252@genedavis.com>, Gene <gene@genedavis.com> posted:
> I've just finished writing this chat program. The back end is perl. (Of
> course, anything important was written in perl:)
are you saying that perl is not important? ;)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Tue, 09 Mar 1999 20:35:24 GMT
From: kstinson@hotmail.com
Subject: Perl and a Here document
Message-Id: <7c40mb$ro$1@nnrp1.dejanews.com>
How can I mimic the "here document" facility in the korn shell using perl?
For Instance I have the following script that I would like duplicate in perl:
#/bin/ksh
DOC_tool <<!
surf
3160
q
!
This script is specific to an application on our RS6000. This script calls
the DOC_tool command. Then at the DOC_tool prompt it enters surf then at the
next prompt it enters 3160 then there is output to the screen that I capture
for processing. Then it enters q to quit. I use a perl program to process
the output of this script. I would like to just have perl do everything
instead of relying on a script to always be there, etc.
thanks,
Kevin
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 09 Mar 1999 16:44:34 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: kstinson@hotmail.com
Subject: Re: Perl and a Here document
Message-Id: <36E59642.6B5F984@giss.nasa.gov>
[posted and mailed]
kstinson@hotmail.com wrote:
>
> How can I mimic the "here document" facility in the korn shell using perl?
> For Instance I have the following script that I would like duplicate in perl:
>
> #/bin/ksh
>
> DOC_tool <<!
> surf
> 3160
> q
> !
>
Simply use a "pipe":
open FH, "| DOC_tool" or die "can't open pipe: $!";
print FH << "EOF";
surf
3160
q
EOF
close FH or die "pipe failed: $!";
Jay Glascoe
--
"Even if you do learn to speak correct English,
whom are you going to speak it to?"
--Clarence Darrow
------------------------------
Date: Tue, 09 Mar 1999 21:03:41 GMT
From: scraig@my-dejanews.com
Subject: Re: Perl format statement question
Message-Id: <7c42b4$2f4$1@nnrp1.dejanews.com>
In article <36E50FF6.A3009370@nospam.com>,
JPAH-FLA <mymail@nospam.com> wrote:
> Hello. I'm using perl to render a HTML doc, and format statements are
> very good at table tags. However, I'm running into one small problem in
> that the field descriptor is conflicting with the HTML tag, for
> instance:
>
> format LISTF =
> <tr>
> <td align="center">@###### </td>
> $conf
> <td align="center" colspan="2"> @<<<</td>
> $dev
>
> the problem is that the field for $dev is considered to be @<<<<, then
> meaningless /td> is appended to it. Of course I really wanted the field
> to be @<<< and the </td> appended.
>
A fix for this case would be to use a different justification, i.e., @|||
instead of @<<<. The contents of the tag are centered anyway.
For more general problems, the recommended way is to insert a '<' character
where you want it, like so
<td align="center" colspan="2"> @<<<@/td>
$dev, "<"
It might be more readable to insert the whole tag,
<td align="center" colspan="2"> @<<<@||||
$dev, "</TD>"
or,
$endtd = '</TD>';
....
<td align="center" colspan="2"> @<<<@||||
$dev, $endtd
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 09 Mar 1999 14:31:58 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Atro Tossavainen <Atro.Tossavainen@iki.fi>
Subject: Re: Referencing arrays with contents of scalars?
Message-Id: <36E5772E.5A6928BD@giss.nasa.gov>
[courtesy copy of post sent to cited author]
Atro Tossavainen wrote:
>
> Basically, I've got a few arrays, and I want to be able to loop over
> them all in one fell swoop, ...
<snip>
foreach my $aref (\@name, \@othername) {
# do something with "$aref"
}
<unsnip>
> ... setting a scalar with the same name as
> the array has ...
<snip>
ouch. Why do you want to do that? How about:
@things = ();
$things[0] = {"scalar" => 0, "array" => []};
$things[1] = {"scalar" => 0, "array" => []};
[... populate things ...]
for my $thing (@things) {
$thing->{"scalar"}++ if subroutine($thing->{"array"});
}
Jay Glascoe
--
"Narf!"
--Pinky
------------------------------
Date: Tue, 9 Mar 1999 22:28:49 +0300
From: "Michael Yevdokimov" <flanker@sonnet.ru>
Subject: RTF=>HTML with extracted GIFs or JPEGs
Message-Id: <7c3smf$bq6$1@bison.rosnet.ru>
Hello!
Does anyone know how to convert RTF (with pics inside) to HTML (with
extracted pics) using normal Perl (not from ActiveState) and without
using CGI.pm or any libs like this.
Note that I can use only features of Perl package, cgi_lib.pl and
scripts like cgi_lib.pl...
If you have please send me such scripts to me directly or send me
urls where I could download them from...
Thanks in advance.
--
Best wishes,
Michael Yevdokimov
Email: flanker@sonnet.ru
ICQ: 30874618
-------------------------------------------------
>> Developers Support Site <<
Web: http://developer.tsx.org
http://www.basicnet.sonnet.ru
-------------------------------------------------
------------------------------
Date: Tue, 09 Mar 1999 20:12:40 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Sendmail
Message-Id: <36E572A8.24D53EAD@ngb.se>
Chris Murray wrote:
>
> You might want to check what the value of $SENDMAIL is set to. You
> might want to see if it looks something like:
>
> $SENDMAIL='/usr/lib/sendmail -t';
> >open (SENDMAIL,"$SENDMAIL") || die "Ain't Gonna Happen";
Then this should probably should look like this:
open (SENDMAIL,"| $SENDMAIL") || die "Ain't Gonna Happen";
otherwise you're not opening a pipe.
HTH
Staffan
------------------------------
Date: Tue, 09 Mar 1999 11:25:20 -0800
From: Ken Li <kli@profdev.sjsu.edu>
Subject: Re: Sendmail
Message-Id: <36E575A0.3258C6B1@profdev.sjsu.edu>
just check
Staffan Liljas wrote:
> Chris Murray wrote:
> >
> > You might want to check what the value of $SENDMAIL is set to. You
> > might want to see if it looks something like:
> >
> > $SENDMAIL='/usr/lib/sendmail -t';
>
> > >open (SENDMAIL,"$SENDMAIL") || die "Ain't Gonna Happen";
>
> Then this should probably should look like this:
>
> open (SENDMAIL,"| $SENDMAIL") || die "Ain't Gonna Happen";
>
> otherwise you're not opening a pipe.
>
> HTH
> Staffan
------------------------------
Date: Tue, 09 Mar 1999 20:59:58 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Shouldn't we have 'perlmonger' ?
Message-Id: <7c4247$23l$1@nnrp1.dejanews.com>
In article <comdog-ya02408000R0703992005510001@news.panix.com>,
comdog@computerdog.com (brian d foy) wrote:
> In article <7bsgtj$p9t$1@nnrp1.dejanews.com>, @l@ <aqumsieh@matrox.com>
posted:
>
> > --Ala
> > $monger->{montreal}->[0];
>
> why are you signing your posts with Nicolas Bertrand's
> monger designation?
Shouldn't we have a perlmonger pod?
% perldoc perlmonger
??
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 09 Mar 1999 18:43:23 GMT
From: Joe Stewart <complangperlmisc@NOSPAMPLEASE.httptech.com>
Subject: Re: Speed-optimizing regular expressions
Message-Id: <824F32276E1EB871.DDFF5CB9DB53259A.A1554F0071F15B37@library-proxy.airnews.net>
On Tue, 09 Mar 1999 17:13:45 GMT, mcafee@waits.facilities.med.umich.edu (Sean
McAfee) wrote:
>open(IN, "master_access_log") || die "Can't open master_access_log: $!\n";
>$n = 0;
>while (<IN>) {
> ($domain, $data) = split / /, $_, 2;
> push @{$domain{$domain}}, $data;
> if (++$n == 100000 || eof) {
> while (($domain, $list) = each %domain) {
> open(OUT, ">>${domain}_access_log")
> || die "Can't append to ${domain}_access_log: $!\n";
> print OUT @$list;
> close(OUT);
> }
> %domain = ();
> $n = 0;
> }
>}
>
>...Come to think of it, this may be the best way overall.
I cut down the number of lines per run to 10000 to prevent
out of memory errors, but the speed difference is phenomenal,
it only took slightly over minute to sort an 84 meg logfile.
The old method would have taken over an hour to run through
all the domains.
Thanks for the help; this makes my day!
-Joe
------------------------------
Date: Tue, 09 Mar 1999 19:48:16 GMT
From: Brad Beiter <thespaceport@my-dejanews.com>
Subject: SSI within CGI
Message-Id: <7c3tts$u4t$1@nnrp1.dejanews.com>
How do i get server side includes to work from within a cgi script? it is in
perl, if that helps.
--Brad Beiter
Visit the SPACEPORT!
http://www.thespaceport.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 09 Mar 1999 11:07:18 -0800
From: Ken Li <kli@profdev.sjsu.edu>
Subject: Re: Why isn't this a race condition ?
Message-Id: <36E57166.D9656E39@profdev.sjsu.edu>
just checking
"Juho Cederstrvm" wrote:
> I've read the FAQ, and this is what I found:
>
> ----- (I still don't get locking. I just want to increment...):
> ...
> Anyway, this is what to do:
> ...
> sysopen(FH, "numfile", O_RDWR|O_CREAT, 0644) or die "can't open numfile:
> $!";
> flock(FH, 2) or die "can't flock numfile: $!";
> ...
> -----
>
> I've understood, that opening and locking should be done by the same
> function. And here two functions are used. So now it seems that I was wrong.
> Could you _please_ explain this to me ?
>
> --
> # this is a perl script which will display my email address
> $_="acbecddeerfsgthriojmkaltmknoolpuqmrbsutsudvowtxfyi";
> s/(.)(.)/$2/eg;s/at/@/;s/dot/./;print $_;
------------------------------
Date: Tue, 09 Mar 1999 20:11:17 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: y2k and 4-digit dates (was Re: foreach and while)
Message-Id: <36E57255.AE8E6F5C@ngb.se>
Tom Christiansen wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, Staffan Liljas <staffan@ngb.se> writes:
> :Then I usually require people to input ISO dates, by
> :stating (yyyymmdd) next to the input field.
>
> That doesn't work for most "regular" people. It's very strange
> to them.
In Sweden it does :-)
Also, I'd prefer not to get courtesy cc's, unless I ask for them...
And more than that: Converting input dates isn't a problem if you know
what people will input. If you don't, I think educating them in the
correct (or at least a good) way of inputting dates is a good thing.
Otherwise you can always split the dates up into three input fields,
which would make things really unambiguous. I think the solution should
depend on who will input the dates - if I'd do something for the
'nobody' on the internet, I'd probably use three fields. If I'd have
users who should input more than one time, I'd prefer to educate them.
Staffan
Staffan
------------------------------
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 5096
**************************************