[8203] in Perl-Users-Digest
Perl-Users Digest, Issue: 1821 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 6 06:08:13 1998
Date: Fri, 6 Feb 98 03: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 Fri, 6 Feb 1998 Volume: 8 Number: 1821
Today's topics:
\Q and variable interpolation in regexps <dehon_olivier@jpmorgan.com>
BER compressed integer (Lars Gregersen)
coder needed for project <eldragon@bc1.com>
Data Conversion vhartley@sybase.com
Re: Data Conversion (Bart Lateur)
Re: Global variable names <kar@webline.dk>
Re: Help! 255-char URL limit passing form values to cgi <dformosa@st.nepean.uws.edu.au>
Re: How to get text into thousands ofHTML-files? (Lars Gregersen)
Re: interpolation bug in Perl5.003_07 (Perl for Win32 b (Joe Myers)
Re: Is file locking necessary? <merlyn@stonehenge.com>
Re: Is there a way to do this? <qdtcall@esb.ericsson.se>
perl pointer puzzle <dberger@uwyo.edu>
Re: Perl screwed by IIS4 upgrade <ldanna@hotmail.com>
Re: posix::strftime (core dumped) <pas@unh.edu>
Re: Quickie: regexp for valid e-mail addresses <dfetter@shell4.ba.best.com>
Re: Redirect with cookies ??? <kbo@kmd.dk>
Re: Redirecting STDIN and STDOUT to Internet <xxTony.Curtis@vcpc.univie.ac.at>
Re: Regular expression expander <rjk@coos.dartmouth.edu>
Re: Search takes Forever (Lars Gregersen)
Re: searching by file creation/modification date? <merlyn@stonehenge.com>
security problem <ramesht@netfxt.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 Feb 1998 10:04:27 +0100
From: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: \Q and variable interpolation in regexps
Message-Id: <njzlnvpcdes.fsf@jpmorgan.com>
Hi,
I just came across this problem of using \Q in regexps:
The following snippet of code will describe it:
#!/usr/bin/perl -w
$pattern = '.*\\Qsomething\\E.*';
print "Matched\n" if 'noise--something--noise' =~ /^$pattern$/;
_END_
This does not yield the expected "Matched".
Whereas:
#!/usr/bin/perl -w
print "Matched\n" if 'noise--something--noise' =~ /^.*\Qsomething\E.*$/;
_END_
does.
It looks as though perl does not interpret the \Q and \E after having
interpolated the variable. Is this behaviour documented (I could not
find anything relevant in 'man perlre' or perlfaq)? Is it (or should
it be considered) a bug?
I also recently discovered what I think is a bug:
$string =~ /\Q\E/;
is considered a syntax error. (I'm using perl 5.004_04 on solaris).
But:
$pattern = '';
$string =~ /\Q$pattern\E/;
is not a syntax error, nor a runtime error.
What's wrong there? Am I missing something?
Thanks for your feedback on these matters.
Olivier Dehon
------------------------------
Date: Fri, 06 Feb 1998 09:49:14 GMT
From: lg@kt.dtu.dk (Lars Gregersen)
Subject: BER compressed integer
Message-Id: <34dad989.8425815@130.228.3.8>
Hi
I've seen in recent versions of Perl that pack has a new format 'w'.
What is its origin? What does BER stand for? What is its intended use?
I'm thinking about using it for storing offsets into files where the
varying lengths of the pack'ed information is great since most files
(on my system) are short and few are long.
Is the BER compressed integer portable between big-endian and
little-endian machines?
I've been trying to pack negative values using 'w' and it seems to go
OK, but the unpack'ing gives me a positive value. Is this an error of
the implementation in Perl or does 'w' not handle negative values?
Lars
Lars Gregersen, M.Sc., Chem. Engng.
Technical University of Denmark
Department of Chemical Engineering
E-mail : lg@kt.dtu.dk
Homepage: http://www.gbar.dtu.dk/~matlg/
------------------------------
Date: Fri, 06 Feb 1998 02:13:49 -0800
From: Aaron Dragushan <eldragon@bc1.com>
Subject: coder needed for project
Message-Id: <34DAE25D.6C10@bc1.com>
Hello all,
I am working on an exciting web project, which is too big to do alone.
I am looking
for a coder. I can code some cgi, but my skills lie more in marketing
and online promotion. I'm looking for someone who dreams in cgi,
seeking a cool project to work on!
The site is the first in a series of sites. It is being created to help
visitors choose the best movie for them without reading a whole bunch of
reviews. If you'd like to check it out, it's at
http://www.moviewizard.com/
Note: The forms on the site don't work yet... it isn't finished yet,
but there is enough that you can get a feel for the project.
Aside from satisfying an urge to create something really neat, the site
could make some money. It could generate income through targetted
banner advertising, product merchandizing, selling moviegoers'
preferences (not profiles) to entertainment industry companies, etc.
I am a student, without deep pockets, perhaps we could come to some
arrangement,
with some combination of:
- experience with a really neat project, and onsite-credit
(this ought to be a popular site)
- links to you and promotion of your company/service
- % of future revenue
- advertising for your service
If it is successful (and all indications thus far indicate so) the
project may be the first in a series on networked sites.
Thanks for your time!
- Aaron Dragushan amd_@usa.net
------------------------------
Date: Fri, 06 Feb 1998 00:01:12 -0600
From: vhartley@sybase.com
Subject: Data Conversion
Message-Id: <886744299.1197277192@dejanews.com>
Does anyone know of any modules for converting signed decimal
and packed fields to the Perl numerics and vice versa.
Problem: I get an ASCII file thats created by a COBOL program which
writes a money field using S9999V99. I need to convert this field to a
Perl numeric, do some math, then write the result in the same original
format.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 06 Feb 1998 10:28:38 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Data Conversion
Message-Id: <34e3e444.9175166@news.tornado.be>
vhartley@sybase.com wrote:
>Does anyone know of any modules for converting signed decimal
>and packed fields to the Perl numerics and vice versa.
>Problem: I get an ASCII file thats created by a COBOL program which
>writes a money field using S9999V99. I need to convert this field to a
>Perl numeric, do some math, then write the result in the same original
>format.
I don't know Cobol. So I don't know what "S9999V99" means. But I'm
pretty sure you don't need any modules. unpack, and pack or sprintf
should do.
My guess: "S" is for sign, and then 4 digits. but what is "V"? And then
two more digits. Yup, unpack (using template 'A5AA2' or similar) or a
regexp, and sprintf.
HTH,
Bart.
------------------------------
Date: Fri, 06 Feb 1998 10:00:31 +0100
From: Kaare Rasmussen <kar@webline.dk>
Subject: Re: Global variable names
Message-Id: <34DAD12F.9BE3E1A4@webline.dk>
> You may want to try returning a reference to whatever you variable you
> create inside the function or module. For a subroutine, here is an
> example:
Thabks for the reply. But tell me, does it return the name of the
variable too? And how do I return more variables than one?
I'm asking because I don't have a Perl right here where I am now. I will
try your suggestion tonight.
------------------------------
Date: 6 Feb 1998 07:10:26 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Help! 255-char URL limit passing form values to cgi
Message-Id: <886748988.657719@cabal>
In <34D91797.374E@nicom.com> Steve Palincsar <palincss@nicom.com> writes:
>Abigail wrote:
>>
>> James Munroe and Tricia O'Neill (eccles@astral.magic.ca) wrote on 1618
>> September 1993 in <URL: news:34D8562F.4F59@astral.magic.ca>:
>Was this stuck in a time warp?
while (1) {
print <<EOF;
Its the september that nerver ends
It gose on an on my frends
Some newbies started it
not knowing what it was
and now where stuck in it because
EOF
}
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Fri, 06 Feb 1998 09:33:42 GMT
From: lg@kt.dtu.dk (Lars Gregersen)
Subject: Re: How to get text into thousands ofHTML-files?
Message-Id: <34dacd49.5289079@130.228.3.8>
On Thu, 05 Feb 1998 21:10:49 GMT, aschmidt@student.uni-kassel.de
wrote:
>Hello,
>I'm not sure whether this mail is compatible with this list's policy.
>If not: excuse me.
You're lucky, It is!
[I guess you know what you're doing so I've snipped a lot. Try to make
posts short and make the Subject describe your problem]
>But I don't know,
> - how to let perl (succesivly) open every file in a given folder,
Read about 'opendir', 'readdir', 'closedir' in perlfunc. These methods
are preferred when you have thousands of files. Also read about 'glob'
(in perlfunc) and 'I/O Operators' (in perlop). I guess you already
know about open and close ;-)
> - how to let it decide whether the file should be manipulated by
>method1 or method2 (according to the HTML-structure of the article)
If the files are short (say less than 50 kb) you can just slurp in the
file using
@file = <INFILE>;
either go line by line through the file using 'foreach' or 'grep' to
see if you have a type one or type two file (you didn't state what
differences there were so I can't help you more specifically).
If the files are large you may have to use something like
while(defined($line=<INFILE>))
{
if ($line =~ /match_criteria_type_1/) {$type = 1;last;}
if ($line =~ /match_criteria_type_2/) {$type = 2;last;}
}
seek(INFILE, 0, 0);
if ($type==1)
{
&do_1();
} else {
&do_2();
}
remember to 'open' and 'close' INFILE as you find appropiate.
>- how to close them after editing and go to the next, still not
>manipulated file.
>As you can see, I don't know how to construct the appropriate loops
>and if'n'else.
What you have to do is:
- find the file names using readdir
- make a loop over the filesnames using foreach
-- determine file type
-- do somthing based on the file type
I hope this helps
Lars
Lars Gregersen, M.Sc., Chem. Engng.
Technical University of Denmark
Department of Chemical Engineering
E-mail : lg@kt.dtu.dk
Homepage: http://www.gbar.dtu.dk/~matlg/
------------------------------
Date: Fri, 06 Feb 1998 06:28:24 GMT
From: joe31416@voicenet.com (Joe Myers)
Subject: Re: interpolation bug in Perl5.003_07 (Perl for Win32 build 315) - send.zip (0/1)
Message-Id: <c4yC.40$q64.407787@news3.voicenet.com>
Mike Heins <mike@ns.minivend.com> wrote:
>Joe Myers <joe31416@voicenet.com> wrote:
>> Running Activeware's Perl5 (downloaded file Pw32i315.exe), I
>> encounterd strange results, after hacking at the script, I've isolated
>> the program to its simplist state:
>> Input file (File.In): ilogout% = True
>> Script file (test.pl): printf("$_");
>> invocation: perl -w -n test.pl File.In
>> Clearly the output ought to be identical with the input, but it's not;
>> here it is:
>> ilogout= True
>> In otherwords, the '% ' got eaten.
<snip>
>This is the usual -- most bugs found by new Perl programmers are in
>their scripts and not in Perl.
> print $_;
>is what you want. The quotes are superfluous, and you don't use
>printf unless you need its formatting. It WILL swallow % signs --
>try %% instead of %.
> $ot = sprintf("%04d) %s", ++$nlines, $_);
>That is what you ultimately (appear to) want.
Thanks Mike, of course. The problem was masked because originally I
was prepending line nos. to an input file, and I wrote
printf("%04d) $_", ++$nrec);
instead of
printf("%04d) %s", ++$nrec, $_);
Interestingly enough, Perl4.036 and Perl5.004 did NOT swallow the "% "
from the input record while Perl5.003 did, but that's an oddity, not a
bug, as "%" is magic in that context.
Joe
------------------------------
Date: 06 Feb 1998 00:58:52 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: MARTIN@RADIOGAGA.HARZ.DE
Subject: Re: Is file locking necessary?
Message-Id: <8cu3adnozn.fsf@gadget.cscaper.com>
>>>>> "Martin" == Martin Vorlaender <martin@RADIOGAGA.HARZ.DE> writes:
Martin> Iain Chalmers (bigiain@mightymedia.com.au) wrote:
Martin> : you really should check out Randal Schwartz's stuff on his website:
Martin> : <http://www.stonehenge.com/merlyn>
Martin> Minor glitch: that should be /~merlyn
Not at all! My *old* address required that when I was sharing my
website with the 30,000 other users at Teleport. I've had my own
virtual server for over a year now, so the ~ is not needed. (It
works, but is deprecated, and will only cause an extra trip between
you and me.)
Martin> Yup. All of the WebTechniques articles are great, IMHO.
>>blush<<
Specifically, the WT columns are at:
http://www.stonehenge.com/merlyn/WebTechniques/
and the Unix Review columns are at:
http://www.stonehenge.com/merlyn/UnixReview/
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 207 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: 06 Feb 1998 09:35:21 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: Is there a way to do this?
Message-Id: <isbtwlqgfq.fsf@godzilla.kiere.ericsson.se>
mcafee@joust.rs.itd.umich.edu (Sean McAfee) writes:
> Is this kind of thing even possible?
Have a look at the perlxstut, perlxs and perlembed manpages.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: Thu, 05 Feb 1998 23:44:25 -0700
From: Damian Berger <dberger@uwyo.edu>
Subject: perl pointer puzzle
Message-Id: <34DAB149.D4D5E05D@uwyo.edu>
I am trying to do some pointer de-referencing, but can't get perl to
de-reference correctly... here is the script that illustrates my
problem.
$temp{'var'} = "variable";
$variable = "output_1";
$reference = \$$temp{'var'}; #supposed to place the string "$variable"
in $reference
print $$reference . "\n"; #should print string "output_1"
$temp = "variable_2";
$variable_2 = "output_2";
$reference_2 = \$$temp;
print $$reference_2 . "\n"; #prints the string "output_2"
The first block of code does not de-reference, whereas the second one
does. My assumption is that the line $reference = \$$temp{'var'} does
not actually replace $temp{'var'} with the characters 'variable' so that
'$variable' can get stored in $reference. Why is this, and how do I
correct it?
The array %temp{} is necessary in the actual program for which I would
like to implement this.
Thanks
Damian Berger
dberger@uwyo.edu
------------------------------
Date: Fri, 06 Feb 1998 01:11:48 -0500
From: Larry D'Anna <ldanna@hotmail.com>
Subject: Re: Perl screwed by IIS4 upgrade
Message-Id: <34DAA9A4.E04D62E7@hotmail.com>
Hsu, Chang Cheng wrote:
>
> Hi,
>
> 1) my perlscripts stopped working after upgrade. i get the error:
>
> Can't open perl script "_private": Permission denied.
>
> "_private" is a directory used by Interdev or Frontpage.
>
> 2) IIS4 upgrade nuked my all my script maps in registry. i put the ".pl"
> script map back, but still get same error.
>
> 3) maybe IIS4 doesn't need those script maps. its got this "Application
> settings" feature in MMC that i can use to associate Perl interpreter
> with ".pl", but still get smae error.
>
> i did remember to restart the server each time.
>
> i appreciate all the nice new features, but now my mission-critical site
> is useless no matter how many new features i get.
>
> help!
>
> thanks
>
> chang
Thats what happens when you use a microsloth server :)
---------------------------------------------------
|Democracy is the worst system of government. --
|Except for all the others
| -Winston Churchill
---------------------------------------------------
Larry D'Anna "eschew obfuscation"
------------------------------
Date: 6 Feb 1998 09:34:22 GMT
From: Paul A Sand <pas@unh.edu>
Subject: Re: posix::strftime (core dumped)
Message-Id: <6beleu$23j@mozz.unh.edu>
>> > POSIX::strftime( "%H:%M, on %D", localtime());
>> > gives a nice Segmentation fault under
>> > - RedHat Linux/Intel 5.0 (glibc)
>> > - Perl 5.004
>> >
>> > Anybody seen/solved this problem ?
Red Hat botched the Perl compile when moving to glibc. I wound up
recompiling from source. What you need to do (apparently) is to
uncomment the line
POSIX_cflags='ccflags="$ccflags -DSTRUCT_TM_HASZONE"'
in hints/linux.sh before compiling. That file (which the Red Hat folks
apparently didn't read) explains why it's necessary. I assume Red Hat
will fix this someday.
(Disclaimer: I didn't come up with this on my own; Lance Brown of NIH
gave me the fix.)
--
-- Paul A. Sand | Bill Gate has done many goodies to the
-- University of New Hampshire | world of computing. But, on the dark side,
-- pas@unh.edu | Microsoft has ruined all the concepts and
-- http://pubpages.unh.edu/~pas | beauties of Computer Science. (S. Saengpetch)
------------------------------
Date: 6 Feb 1998 08:36:49 GMT
From: David Fetter <dfetter@shell4.ba.best.com>
Subject: Re: Quickie: regexp for valid e-mail addresses
Message-Id: <6bei31$kr$1@nntp1.ba.best.com>
Chris Nandor <pudge@pobox.com> wrote:
> In article <6bac3j$55o$1@nntp1.ba.best.com>, David Fetter
> <dfetter@shell4.ba.best.com> wrote:
> # #!/usr/bin/perl
> # $_=q{M<WES=&5M('$K96-H;R`B(B!\;6%I;"!P<F5S:61E;G1`=VAI=&5H;W5S92YG
> # M;W8@+7,@(DD@=VEL;"!K:6QL('EO=2$B*SMP<FEN="`B66]U(&IU<W0@=&AR
> # @96%T96YE9"!T:&4@4')E<VED96YT+"!M;W)O;B%<;B(`};s|^.*$|unpack("u*",$&)|ees;
> s|^.*$|unpack("u*",$&)|ees;
> s|^.*$|print unpack("u*",$&)|ees;
> ^^^^^^
I munged it just in case some twinkletoes decided to run it without
looking. :)
--
David Fetter 888 O'Farrell Street Apt E1205
shackle@ren.glaci.com San Francisco, CA 94109-7089 USA
http://www.best.com/~dfetter +1 415 567 2690 (voice)
print unpack ("u*",q+92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R"@``+)
Governments, like diapers, should be changed often, and for the same reason.
------------------------------
Date: Fri, 06 Feb 1998 10:37:35 +0100
From: Kim Bo Hansen <kbo@kmd.dk>
Subject: Re: Redirect with cookies ???
Message-Id: <34DAD9DF.4064@kmd.dk>
Thomas R. Hall wrote:
>
> : > print "Set-Cookie: MYNAME=Bob.Smith\n";
> : > print "Location: /cgi-bin/newprogram.pl\n\n";
> : >
> :
> : Which will indeed set a cookie on the client side, and redirect the
> : client to newprogram.pl. The problem is that newprogram.pl does not see
> : your cookie MYNAME. If you initiate another connection to newprogram.pl,
> : it will then see MYNAME, but not if it is called on a redirect.
>
> Check out the rest of my message. If you notice, I mention that if you
> perform a redirect to newprogram.pl INSTEAD OF /cgi-bin/newprogram.pl, the
> cookie WILL, in fact, be readable by the script.
>
> I am using this successfully on 30+ CGI programs with 6000+ users...
>
> --
> # Thomas R. Hall <trhall@indiana.edu> BPO Web Services Coordinator
> # http://php.indiana.edu/~trhall/ Indiana University Bloomington
> # RSA KeyID: 0x8F6DFD27 DSS/DH KeyID: 0x443AE82D trhall@acm.org
>
> --
> --
> Thomas R. Hall <trhall@indiana.edu> BPO Web Services Coordinator
> http://php.indiana.edu/~trhall Indiana University Bloomington
> RSA KeyID: 0x8F6DFD27 DSS/DH KeyID: 0x443AE82D trhall@acm.org
Thank You for Your answer, I almost have my program working now.
However, I still get an anoying problem when using Your code:
print "Set-cookie: Return_Code=Bob.Smith\n";
print "Location: contract_example.pl\n\n";
which is more or less what you suggested (I am running winnt, so I use
the relative location reference). This results in my server to jump to
the location without setting the cookie.
I then discovered that this is due to the "\n" control at the end of the
set-cookie line. if I removed it, the cookie was set correctly, but then
the location line naturally did not work, as the printed line looked
like this:
Set-cookie: Return_Code=BobLocation: contract_example.pl
which the browser do not understand much of (I don4t blaim it).
I tried to put in: space, ;, \r instead of the \n, but none of it
helped.
If I put in "\n\n" at the end of the set-cookie line the cookie is also
set correctly, but the browser still does not understand the location
line. ex:
print "Set-cookie: Return_Code=Bob.Smith\n\n";
print "Location: contract_example.pl\n\n";
It looks like each lines has to end with "\n\n" in order to be
interpretated correct, but then the following line is skipped.
Do you have any suggestions to this problem/have you
experienced the same ??
Thanks in advance
Kim
------------------------------
Date: 06 Feb 1998 09:24:56 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
Subject: Re: Redirecting STDIN and STDOUT to Internet
Message-Id: <7xafc56syv.fsf@beavis.vcpc.univie.ac.at>
Re: Redirecting STDIN and STDOUT to Internet, Anders
<andersma@idt.unit.no> said:
Anders> I am making a simple client server system, the idea
Anders> is to let users via a java applet access a console
Anders> application at server side.
Anders> I have tried to use open2 to redirect stdin and
Anders> stdout. The result is that the input from client
Anders> works ok, but the output which should end up at
Anders> client side is printed out on the server console.
How about
Net::DummyInetd
will that do what you want??
hth,
tony
------------------------------
Date: Fri, 06 Feb 1998 01:35:47 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Regular expression expander
Message-Id: <34DAAF47.C3E771C1@coos.dartmouth.edu>
Adam Krolnik wrote:
>
> After trying to decipher someone else's regular expression code, we
> wondered if anyone has though about using a regular expression
> to generate text.
>
> Instead of using regular expressions to match text, instead take
> a regular expression and generate legal combinations of text
> that it describes. This would seem to be a helpful tool for
> writing correct regular expressions as one could directly see
> what is being specified. I do understand that it would not be able
> to exhaustively generate the combinations, but I would think that
> one could assign limits to the operators, e.g. \d == {0,1,2}
> + == {1,2}, * == {0,1}, . == {.,a,%}. Since a program like this
> would have to parse the regular expression, I think it would have
> to use part of the regular expression compilation code and have a
> different evaluator - an expander instead of a matcher.
Well, since you asked...
Here's something I started working about a week ago, inspired by
another thread. Then I realized it would work much better if it
were written like a regex parser, using a finite automata and such.
Anyway, for what it's worth, here is matcher.pl
It generates a match for a regular expression. It's worked for
the ones I've tried it on so far. Note that it does not handle
Perl's extended regular expression syntax: (?...).
Aside from that, feel free to find regexes where it screws up.
Chipmunk
~> cat matcher.pl
#!/usr/local/bin/perl
use strict;
my($regex) = shift || die "Usage: $0 regex\n";
my(%bslash) = ( # mapping of backslashed characters
a => "\a", # to matching characters
n => "\n",
r => "\r",
t => "\t",
f => "\f",
e => "\e",
d => '0',
D => '#',
w => 'A',
W => '&',
's'=> ' ',
S => '_',
);
my($allchars) = pack("C*", 0x00 .. 0xFF);
# array of all characters
my(@backrefs) = (undef); # array to store back references
my($match) = &match($regex); # find match for regex
print
qq{"\Q$match\E" =~ /$regex/ returns },
($match =~ /$regex/ ? 'True' : 'False'),
"\n";
print join("\n", "Backrefs: ", @backrefs[1..$#backrefs], "");
# find a string which matches regex
sub match {
my($regex) = shift;
$regex =~ s/([^\\][?*+\}])\?/$1/g; # remove non-greedy quantifiers
$regex =~ s/([^\\])([*+?])/$1\{1\}/g; # quantifiers -> {1}
$regex =~ s/([^\\]\{)0([,\}])/$ {1}1$2/g; # always match at least once
$regex =~ s/([^\\])\{(\d+)(?:,\d*)?\}/$1\{$2\}/g;
# always match minimum
return &match_recurse($regex); # recursively find match
}
# find a string which matches regex
# recurses on parenthesized sub-regexes
sub match_recurse {
my($regex) = shift; # regex to find match for
my($match) = ''; # match being found
my($c); # current character in regex
while (length $regex) {
my($submatch) = ''; # match for current char/sub-regex
$c = substr($regex, 0, 1); # get next char from regex
substr($regex, 0, 1) = '';
if ($c eq '\\') { # backslash
if ($regex =~ s/^([1-9])(?!\d)//) {
# handle back references
$submatch = $backrefs[$1];
} elsif ($regex =~ s/^([0-3][0-7]{1,2}|x[0-9a-fA-F]{1,2}|c.|0)//) {
# handle octal, hex, control, null
eval qq{\$submatch = "\\$1"};
} else { # handle everything else
$c = substr($regex, 0, 1); # get next char
substr($regex, 0, 1) = '';
if (exists $bslash{$c}) {
$submatch = $bslash{$c}; # special meaning for \char
} else {
$submatch = $c; # no special meaning
}
}
} elsif ($c eq '|') { # alternation: match first choice
return $match;
} elsif ($c eq '(') { # parenthesized sub-regex
my($temp) = '';
my($level) = 1;
push(@backrefs, ''); # allocate back reference
my($br_ref) = \$backrefs[$#backrefs];
# save ref to back reference
while ($level > 0 and length $regex) {
$c = substr($regex, 0, 1);
substr($regex, 0, 1) = '';
if (length($temp) and substr($temp, -1) ne '\\') {
if ($c eq ')') {
$level--;
} elsif ($c eq '(') {
$level++
}
}
$temp .= $c;
} # find matching close paren
$temp =~ s/\)$// or # remove close paren
die "Mismatched parentheses in regex.\n";
$submatch = &match_recurse($temp);
# find match for sub-regex
$$br_ref = $submatch; # store as back reference
} elsif ($c eq '[') { # character class
$regex =~ s/^(\^?(?:\\.|[^\]])+)\]//;
my($class) = $1;
($submatch) = $allchars =~ /([$class])/;
} elsif ($c eq '.') { # match any character
$submatch = '.';
} else { # non-special character
$submatch = $c;
}
if ($regex =~ /^\{/) { # check for quantifier
$regex =~ s/^\{(\d+)\}//;
$submatch = $submatch x $1;
}
$match .= $submatch; # append to match being built
}
return $match;
} # sub match_recurse
------------------------------
Date: Fri, 06 Feb 1998 08:41:29 GMT
From: lg@kt.dtu.dk (Lars Gregersen)
Subject: Re: Search takes Forever
Message-Id: <34dac90c.4204161@130.228.3.8>
On Thu, 5 Feb 1998 08:25:01 -0500, "Franklin L. Petersen"
<orangutan@grungyape.com> wrote:
>I need some help, and I hope it's simple.
>
>I have a web form, where people can enter part numbers. It then searches a
>flat txt file outputted nightly for all matches (some partnumbers have
>multiple responces). I wanted to simply just query the database, but this
>question assume it cannot be done. Instead, it searches this text file that
>is about 3 megs in size. As you can guess, it takes way too long.
A search in a 3Mb file shouldn't take 'forever' even if you do it the
quick-and-dirty way. If there ie really no patterns in the part
numbers you can explore you may have a hard time speeding it up.
Do you always query for an exact match? If so, you could try one of
the DBM modules that will give you matches instantly.
Are you searching using a regular expression entered by the user? If
so, you have little choice but to go through the file and seach every
part number in the data base. There are some implementations of that
are more efficient than others. If you do
@part_numbers = <INFILE>;
you can easily be allocating 6-12Mb which may take a long time on your
machine. Going though the file with
while(defined($line=<INFILE>))
{ if ($line =~ /$pattern/o) &do_something() }
is much faster! The fastest way may be that you slurp in the file
using 'read' (see perlfunc) and design your regex to search for
multiple matches on multiple lines (using the g and m modifiers).
Try to explore any pattern in the part numbers or in the regex you
search for. E.g. do you always know the first letter/digit? Then split
(or sort) the database by that key and search a subset of the
database.
If you are doing zillions of searches per second and have customers
waiting with money in their hand trying to buy stuff you may have to
actually go and by a book on data structures and searching and such,
have fun!
I hope this helps.
Lars
Lars Gregersen, M.Sc., Chem. Engng.
Technical University of Denmark
Department of Chemical Engineering
E-mail : lg@kt.dtu.dk
Homepage: http://www.gbar.dtu.dk/~matlg/
------------------------------
Date: 06 Feb 1998 00:55:24 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: mwang@alhena.ibk.ml.com (Michael Wang)
Subject: Re: searching by file creation/modification date?
Message-Id: <8cyazpnp5f.fsf@gadget.cscaper.com>
>>>>> "Michael" == Michael Wang <mwang@alhena.ibk.ml.com> writes:
Michael> What I do not know is under at what circumstances can access time be
Michael> earlier than modification time?
This is not a Perl question, but I can give a Perl answer.
You can set it artificially:
$now = time;
utime $now - 1, $now, "somefile";
Or, on some flavors of Unix, "access time" means only "open for read",
so the atime is *not* updated on a "write only" access, like open for
appending. Check your local listings for a theatre near you. Offer
void where prohibited by law.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 207 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: Fri, 06 Feb 1998 15:45:34 +0530
From: "Ramesh C. Pandey" <ramesht@netfxt.net>
Subject: security problem
Message-Id: <34DAE2C6.17BE@netfxt.net>
Greeting,
I am trying to create a restricted site. Can you suggest me some
perl script which manipulate .htaccess and .htpassword file for user
verification.
Can I use msql tables for user verifiaction without any security problem
I want to store users all information in these tables including
password, accessable file and other details etc. Or do anyone have some
interaface for .htaccess and .htpassword for msql.
Suggest me something with security related.
Thanks
Ramesh
------------------------------
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 1821
**************************************