[19179] in Perl-Users-Digest
Perl-Users Digest, Issue: 1374 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 25 06:05:33 2001
Date: Wed, 25 Jul 2001 03:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996055507-v10-i1374@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 25 Jul 2001 Volume: 10 Number: 1374
Today's topics:
Re: CGI Uploads <ron@savage.net.au>
CORBA-MICO and Perl <tkangas@cc.tut.fi>
Re: Detecting cookies. <mbudash@sonic.net>
Re: emacs etags default in cperl mode <nospam-abuse@ilyaz.org>
Re: encrypt a password <Tassilo.Parseval@post.rwth-aachen.de>
FAQ: How can I compare two dates and find the differenc <faq@denver.pm.org>
Re: FAQ: Why aren't my random numbers random? <tsee@gmx.net>
Re: Filehandle major weirdness in recursive I/O (Andrew Mayo)
GetLongPathName()? <gm@magpage.com>
Re: GetLongPathName()? <gm@magpage.com>
Re: Hashes of arrays <goldbb2@earthlink.net>
Re: How do I count the number of characters in a string <pne-news-20010725@newton.digitalspace.net>
Re: mod_perl for NT <bart.lateur@skynet.be>
newbie semantic (non-code) question -"what the pros cal <"goodrow"@opencity. com>
Re: Open files <dbe@wgn.net>
Re: problems with open <bholness@nortelnetworks.com>
Re: probs. passing filehandels and scope issues <goldbb2@earthlink.net>
Re: Regular Expression Reduction <goldbb2@earthlink.net>
Re: Regular Expression Reduction <paul.johnston@dsvr.co.uk>
Re: Regular Expression Reduction <bart.lateur@skynet.be>
Re: Regular Expression Reduction <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 25 Jul 2001 14:04:21 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: CGI Uploads
Message-Id: <cCr77.97437$Rr4.572087@ozemail.com.au>
Static-Pulse (Dead-liner?)
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Eric Bohlman <ebohlman@omsdev.com> wrote in message news:9jiu32$20h$1@bob.news.rcn.net...
> Static-Pulse <darkbeast@darkbeast.com> wrote:
> > Can anyone point me to sample code that demonstartes how to construct
> > a Perl/cgi script that handles data presented through the <input
> > type=file> html tag? I'm looking through google/deja archives, but so
Here's one demo: http://savage.net.au/Perl-tutorials.html (Tut # 37)
------------------------------
Date: Wed, 25 Jul 2001 06:41:51 +0000 (UTC)
From: Kangas Tomi <tkangas@cc.tut.fi>
Subject: CORBA-MICO and Perl
Message-Id: <9jlpne$681$2@news.cc.tut.fi>
Hi,
I'm trying to make a Corba client with perl and I'm using MICO version 2.3.3 and binding CORBA-MICO-0.6.0.
The compilation and the installation of those above are succesful, but whatever I try to do (start a server or run a client), I get
this:
Can't load '/opt/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/CORBA/MICO/MICO.so' for module CORBA::MICO: ld.so.1: perl: fatal:
relocation error: file /opt/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/CORBA/MICO/MICO.so: symbol
__tiQ214PortableServer21DynamicImplementation: referenced symbol not found at /opt/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm
line 169.
My system is SunOS 5.6 Generic_105181-21 sun4u sparc SUNW,Ultra-5_10 and my gcc is
gcc version 2.95.2 19991024.
Does anyone know what the problem could be and what should I do?
Tomi Kangas
tomi.kangas@tut.fi
------------------------------
Date: Wed, 25 Jul 2001 05:12:11 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Detecting cookies.
Message-Id: <mbudash-ADF56F.22121124072001@news.sonic.net>
In article <LEj77.18309$SK6.2111666@news6-win.server.ntlworld.com>,
"Nathan Randle" <nathan.randle@ntlworld.com> wrote:
> I'm am writing a script to detect if a cookie is there. I want the cookie
> to die once the browser is closed. So how do you do all this?
>
> if (cookie doesn't exist) {
> Do all this
> }
>
> how do you say the 'cookie doesn't exist' bit?
since you're in a perl ng, here's a perl way (untested):
use CGI qw/:standard/;
unless (cookie('cookie_name')) {
# do all this
}
> and how do you declare a cookie in a Meta tag that will die once the
> browser is closed?
huh? in a meta tag?? all i now is that if you don't specify an
expiration date, the cookie is not persistent; i.e., it goes away when
the browser is closed.
if you're using CGI.pm (you are, aren't you?), see:
http://stein.cshl.org/WWW/software/CGI/
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Wed, 25 Jul 2001 06:15:09 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: emacs etags default in cperl mode
Message-Id: <9jlo5d$25s0$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Badari Kakumani
<badarik@yahoo.com>], who wrote in article <3B5E0259.E3348BC5@yahoo.com>:
> i use emacs cperl mode for writing the perl code.
> i am starting to use etags facility. when i search
> for a tag using M-. (find-tag) command in emacs, the default
> appears to be the word at which the cursor is
> located. typical perl function calls we have
> are of the form <package>::<function> and that is
> selected as the default. but etags needs only <function>
> to find the tag. so is there a way to influence
> etags find-tag routine to ignore the <package>::
> prefix in the word around cursor and select just <function>
> as the default value to look for?
The function to extract the word for etags' default is customizable.
CPerl has cperl-mode-hook.
Enough said,
Ilya
------------------------------
Date: Wed, 25 Jul 2001 08:35:47 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: encrypt a password
Message-Id: <3B5E68C3.5080409@post.rwth-aachen.de>
nobull@mail.com wrote:
>
>You can obscure the password such that a person looking at the source
>and not deliberately trying to discover the password will not
>unintensionally become aware of the password.
>
>If this is your goal then the simplest obscuring algorithm to
>implement in Perl is a simple XOR:
>
Oh, there might be something else. Of course, this is no security since
the code is still there. He could make a module and obscure it by using
the Smirch module, All the module would do is define a variable
$password and export that.
$password = "very_secret";
becomes, once smirched:
$==$';$;||$.|$|;$_='*$(^@(%_+&~~;;);@-,./.);;#);;#););,.;_);~~,.;;~~@-;#.%~~@-~~~~);,.,.;.);~~);*+;.;_)
;;#,.;.,.;#);~~,.;.);;;~~~~;#-(@-__&$#%^';$__='`'&'&';$___="````"|"$[`$["|'`%",';$~=("$___$__-$[``$__"|
"$___"|("$___$__-$[.%")).("'`"|"'$["|"'#").'/.*?&([^&]*)&.*/$'.++$=.("/``"|"/$[`"|"/#'").(";`/[\\`\\`$_
_]//`;"|";$[/[\\$[\\`$__]//`;"|";#/[\\\$\\.$__]//'").'@:=("@-","/.","~~",";#",";;",";.",",.",");","()",
"*+","__","-(","/@",".%","/|",";_");@:{@:}=$%..$#:;'.('`'|"$["|'#')."/(..)(..)/".("```"|"``$["|'#("').'
(($:{$'.$=.'}<<'.(++$=+$=).')|($:{$'.$=.'}))/'.("```;"|"``$[;"|"%'#;").("````'$__"|"%$[``"|"%&!,").${$[
};`$~$__>&$=`;
Tassilo
--
For children with short attention spans: boomerangs that don't come back.
------------------------------
Date: Wed, 25 Jul 2001 06:16:39 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I compare two dates and find the difference?
Message-Id: <bvt77.41$os9.135400448@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I compare two dates and find the difference?
If you're storing your dates as epoch seconds then simply subtract one
from the other. If you've got a structured date (distinct year, day,
month, hour, minute, seconds values), then for reasons of accessibility,
simplicity, and efficiency, merely use either timelocal or timegm (from
the Time::Local module in the standard distribution) to reduce
structured dates to epoch seconds. However, if you don't know the
precise format of your dates, then you should probably use either of the
Date::Manip and Date::Calc modules from CPAN before you go hacking up
your own parsing routine to handle arbitrary date formats.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
04.12
--
This space intentionally left blank
------------------------------
Date: Wed, 25 Jul 2001 08:52:23 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: FAQ: Why aren't my random numbers random?
Message-Id: <9jlq3k$3qt$00$1@news.t-online.com>
"Andras Malatinszky" <andras@mortgagestats.com> schrieb im Newsbeitrag
news:3B5E1491.2E8F8051@mortgagestats.com...
>
>
> PerlFAQ Server wrote:
>
> >Don't call "srand" more than once--you make your numbers less random,
rather
> than more.
>
> Why is that?
Read the man pages.
From perlfunc: "The point of the function is to ``seed'' the rand() function
so that rand() can produce a different sequence each time you run your
program."
Cheers,
Steffen Müller
------------------------------
Date: 25 Jul 2001 02:21:22 -0700
From: ajmayo@my-deja.com (Andrew Mayo)
Subject: Re: Filehandle major weirdness in recursive I/O
Message-Id: <2b20cd9f.0107250121.1ed6c658@posting.google.com>
ajmayo@my-deja.com (Andrew Mayo) wrote in message news:<2b20cd9f.0107240616.379c5d8b@posting.google.com>...
Well, thanks for the responses. I didn't quite anticipate the sarcasm
which wasn't terribly helpful. I do appreciate the help, but folks, do
you have to be quite so snide?
Regarding the comment that the errors came from an unsuccessful open.
I should clarify that the uninitialised filehandle error occurs on
some versions of perl on Windows erratically and does not correlate
with missing or inaccessible files. The real production code obviously
has 'or die' but why clutter up sample code with error trapping.
This example, and the replies, simply confirm that perl is willfully
different in ways that do not map cleanly to any other programming
language I have ever used.
Of course I use 'use strict' in production code but that wasn't the
point either. I said this was a stripped-down canonical case so I
omitted anything not directly relevant to the problem under
discussion.
My question was that I didn't have a mental model for the behaviour of
variables used in file handles. Now that I know that perl does all
kinds of wacky things with them I frankly just respect its design that
much less.
Yes, its a neat language and I use it for all kinds of minor text
processing purposes. But this kind of weird, off the wall cleverness
is just too hippy-dippy for me, I'm afraid. A variable is not supposed
to behave like this and clever stunts like this make debugging about
as meaningful as trying to determine the position and velocity of an
electron simultaneously. Maybe the laws of physics preclude this but
there's no need for computer systems to work this way.
I tolerate, because I must, the fact that almost anything is legal in
perl thus making a simple typo choke the parser some 500 lines later,
and resign myself to keeping a copy of the file BEFORE I changed one
line, so I can backtrack and try making the change again, because for
sure I can't rely on the reported error being within 20 lightyears of
the typo.
But this sort of thing.... why in heavens name does 'open' have to be
so clever. I wanted a file handle in a variable. I didn't want some
kind of silly typeglob and autovivification and magic, thank you very
much. Is there some function that just does the simple and obvious, or
would that be too much to expect?. Terry Pratchett would love this
language, I think..........
------------------------------
Date: 25 Jul 2001 05:04:35 GMT
From: "~greg" <gm@magpage.com>
Subject: GetLongPathName()?
Message-Id: <9jlk13$gp5$0@216.155.33.133>
using perl v5.6.1 built for MSWin32.
There seems to be a Win32::GetShortPathName(longPathName);
- but no Win32::GetLongPathName(shortPathName);
Is this true, and is there a way to get it?
tia,
~greg
------------------------------
Date: 25 Jul 2001 05:13:24 GMT
From: "~greg" <gm@magpage.com>
Subject: Re: GetLongPathName()?
Message-Id: <9jlkhk$i1c$0@216.155.33.133>
uh, - my mistake.
It's there.
It just that O'Reilly's Perl In A Nutshell doesn't say it is.
- sorry all.
~greg
"~greg" <gm@magpage.com> wrote in message news:9jlk13$gp5$0@216.155.33.133...
>
> using perl v5.6.1 built for MSWin32.
>
> There seems to be a Win32::GetShortPathName(longPathName);
> - but no Win32::GetLongPathName(shortPathName);
>
>
> Is this true, and is there a way to get it?
>
> tia,
>
> ~greg
>
>
>
------------------------------
Date: Wed, 25 Jul 2001 01:08:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Hashes of arrays
Message-Id: <3B5E5445.91D60DEC@earthlink.net>
Michael Carman wrote:
>
> W K wrote:
> >
> > David Anderson wrote:
[snip]
> >> Is there any way to create the hash of arrays without having to
> >> set up a loop to put each individual value in?
> >
> > you probably want to create a hash of _references_ to arrays.
> > This would (mistakenly) look like this:
> > $ba{$code} = \@info;
>
> Not if you properly scope your variables:
>
> while (<IN>) {
> chomp;
> my ($code, @info) = split(/\t/, $_);
> $ba{$code} = \@info;
> }
>
> > For reasons explained better elsewhere, you need
> > $ba{$code}= [@info];
>
> Also good, and preferred by some because they feel the former method
> holds a trap for novices.
Another way might be:
while (<IN>) {
chomp; s/([^\t]*)\t?//;
$ba{$1} = [split /\t/];
}
Which avoids the use of a temporary array.
--
I need more taglines. This one is getting old.
------------------------------
Date: Wed, 25 Jul 2001 06:39:04 +0200
From: Philip Newton <pne-news-20010725@newton.digitalspace.net>
Subject: Re: How do I count the number of characters in a string
Message-Id: <25jsltcasfv4qriid3giac3mle9igb3fos@4ax.com>
On Tue, 24 Jul 2001 23:41:02 +0300, "novastar"
<subscriber@novastar.dtdns.net> wrote:
> this one maybe ...
>
> print $var=~s/(.)/\1/g ;
Nope. \1 etc. are deprecated on the right-hand side of a substitution.
You could, of course, use $1 (the suggested equivalent), but why not
just use tr, which is probably faster?
print $var =~ tr/\x00-\xff//;
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Wed, 25 Jul 2001 05:59:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: mod_perl for NT
Message-Id: <73oslt0gifij43f6iffmht7r93unqgui9h@4ax.com>
Bjoern Hoehrmann wrote:
>>There is a mod_perl for NT. Just not for IIS.
>
>Is there a mod_perl for Apache 2.0 _and_ NT? The last time I tried to
>get the latest CVS version running for this envoirement, I failed...
Gee. There's a working mod_perl for Apache 1.3.20. IndigoPerl (see
<http://www.indigostar.com>) comes with it, precompiled and
preinstalled.
--
Bart.
------------------------------
Date: Wed, 25 Jul 2001 02:26:19 -0400
From: Jason Goodrow <"goodrow"@opencity. com>
Subject: newbie semantic (non-code) question -"what the pros call it"
Message-Id: <9jloi8$h9i$1@news.panix.com>
Hello Newsgroup;
Sorry if this is too convoluted - please ignore if annoying.
I'm teaching myself perl (slowly) and keep encountering certain concepts
which seem somewhat fundimental -
my question - "What do the pros call it"
For instance: Say I have a bunch of data serverside that's going to the
client - I put the data in a '_' delimited string so my client-app can
say @array = split string on '_' - (psuedo not perl code)
now say my array elements are all '**' delimited so each @array => split
'**' into more arrays.
Now I have to decide for client server reasons how dense I want to make
the incoming data - say 100 items each a 1k array.
Do I send these at once in one big string or one at a time.
Not asking for specific advice, just wondering what this issue is called
(and if there's a good book - site - FAQ on ... uh ...
conceptual terminology)
I've been making up my own names but I want to know
"What the pros call it"
Thanks for any info
goodrow@panix.com
------------------------------
Date: Wed, 25 Jul 2001 02:39:59 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Open files
Message-Id: <3B5E93EF.F25BAB9F@wgn.net>
Anno Siegel wrote:
>
> According to $Bill Luebkert <dbe@todbe.com>:
> > Rob Kirby wrote:
> > >
> > > I would like to use the Find.pm to traverse a filesystem to create
> > > a list of files that reside in that filesystem and record various
> > > info about each file with the stat.pm module. Is there a module
> > > to obtain a list of open files for a given filesystem?
> >
> > File::Find
>
> How does File::Find help in finding open files? As far as I see,
> the OP intends to use that anyhow.
>
> Finding open files under Unix is not trivial. Some (most?) systems
> have "fuser" these days, but fuser is a relatively expensive operation.
> I would hesitate to apply it indiscriminately to a lot of files.
Sorry mis-read the question. File::Find was for the first sentence
which I mis-read and now realize he already knew that. :(
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Wed, 25 Jul 2001 10:46:05 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Re: problems with open
Message-Id: <9jm4fr$gq2$1@bcarh8ab.ca.nortel.com>
> >sub foo{
> > open( content_f, "<content.html" ) or print "Need content.html\n"
> ^
> > print <content_f>;
> >}
For those who's newsreader shows TTF rather than fixed font, the arrow is
pointing at the lack of semi-colon at the end of the line :)
Took me a while to work out what was wrong with the double quote :)
Ben
------------------------------
Date: Wed, 25 Jul 2001 00:15:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: probs. passing filehandels and scope issues
Message-Id: <3B5E47F8.D8173FD0@earthlink.net>
Jason LaPenta wrote:
>
> Hello,
>
> Why won't this work? I think it should. It's template_f a global?
>
> ########################################
> # process_dir
> #
> sub process_dir {
>
> ...
> seek( template_f, 0, 0 );#SEEK_SET ); # line 124
> while ( $line = <template_f> ) {
> ....
> }
> }
>
> }
>
> open( template_f, "<template.html" ) || print "Need template.html\n";
>
> OUTPUT :
> seek() on unopened file at ./process2.perl line 124.
You're not posting real code, since there is not "or die" after the
seek, and thus nothing which would produce this error message.
Anyway, the problem is most likely that something is calling process_dir
before the open statement.
> How can I get this to work as a global? Or how can I pass template_f?
> I tried it but I got useless errors no matter what I tried.
Read the faq to learn how to pass a filehandle to a subroutine.
Learn to use perldoc.
Also, read perlstyle. You should be using all caps for bareword
filehandles.
--
I need more taglines. This one is getting old.
------------------------------
Date: Wed, 25 Jul 2001 00:55:32 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Regular Expression Reduction
Message-Id: <3B5E5144.477BC865@earthlink.net>
Moonshiner wrote:
>
> I am looking for anything to help me reduce the size of regular
> expressions(regex) being created for code verification. I have
> created regular expressions that will go through Ada code and separate
> the constructs/statements. Example, I have a regex that will locate a
> range. It works fine but the numerical values of a range do not
> necessarily have to be actual numbers, they could be variables. In
> fact, the range values could be a combination of numbers and
> variables. Here is how it is written:
> (posting has messed with the linefeeds and such but hopefully you can
> figure out what I mean.;))
[snip]
Whoo, that's big. Might I suggest that you use the /x modifyer to make it more readable?
> Needless to say - the regex created for $range_definition gets rather
> long (755 characters including parenthesis and other punctuation. I
> would include it but I am having to use a (ugh)Windows box to write
> this and is a totally separate machine. The code is running on Sun
> Unix boxes.
>
> I actually used the syntax chart for Ada from "Software Engineering
> with Ada" by Grady Booch, 1983 to build my regexs. It works rather
> well but I think I should be able to do something to the regexs to
> make them better.
>
> The problem I am trying to solve is how to remove/move the duplicate
> pieces of the regex so that it would be faster and use less memory
> without doing each regex by hand. I realize I could probably do just
> that but I figure that if I can do it using my brain and paper I
> should be able to write a hunk of code to do it. With my luck it will
> not be a trivial pursuit!
You generally can't magically optomize regexes, you have to use your brain. Perl optomizes as much as it can, and unless you're doing something which is of a particular form, you're out of luck.
> The regexs currently being created work but are soooooo long. I have
> had them around 6,000 characters. A lot of the work is done because
> of the or's used to build the regex.
Then optomize the ors.
You have some things backslashed when they shouldn't be, and
non-backslashed when they should be. Also, you seem to be confused
about the behavior of character-classes.
You don't need grouping around a scalar being interpolated, if it is a
Regex object that was produced by qr//.
Writing in parts like \s* will probably be better than using $ows.
Likewise for other small pieces, especially ones with long names.
The string [+-] is parsed as begin-character-class, letters plus through
right-square-bracket. It's an unterminated character class. Use [-+]
instead; the - loses its specialness if it's at the beginning.
As a favor to you, I've changed everything to use qr, and made a few
minor corrections. Hopefully, I'll have fixed all the semantic errors,
leaving you with the logic errors.
$based_literal = qr/
[#]
\w+
[#]/x;
$decimal_literal = qr/
[+-]?\d
[\d_]*?
\.
\d[\d_]*?
$exponent?
\b/x;
$numeric_literal = qr/$based_literal|$decimal_literal/;
$name = qr/\b[a-zA-Z]\w*\b/;
$nm_att = qr/
$name? # $name includes no whitespace...
(?: # does $appos include some in front?
$appos $name?
(?:\s* \( .* \) )?
)?/x;
# do you *really* want the greedy .* there ?
$integer = qr/
(?<![_\d.a-zA-Z])
[+-]?\d+
(?:_?\d+)?
(?![\d.a-zA-Z_#])
/x;
$range_definition = qr/
(?:
$nm_att|
$numeric_literal|
$name \s* [-+] \s* $number|
$integer|[-+]?\d+|
\) # match a lonely ")" ? Probably a mistake.
)
\s* \.\. \s*
(?:
$attribute|
$numeric_literal|
$name \s* [-+] \s* $number|
$name|
$integer|[-+]?\\d+|
\( \s* .* \) # the .* here is greedy... easily a bug.
)
/x;
Why does the start of a range allow a $nm_att, and the end of the range
a $attribute ? Why is a $name allowed at the end of a range, but not
at the beginning ? I think you may need to rewrite most of your REs.
The stuff I wrote is untested, and I hope you don't use it directly.
Learn why I made the changes I did, and use that for rewriting your
program. Also, I would advise you to look into Parse::RecDescent if
you are trying to parse a program.
--
I need more taglines. This one is getting old.
------------------------------
Date: Wed, 25 Jul 2001 09:52:12 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Regular Expression Reduction
Message-Id: <3B5E88BC.B2C73BF6@dsvr.co.uk>
Hi,
> I am looking for anything to help me reduce the size of regular
> expressions(regex) being created for code verification.
You may find that lex and yacc, or the GNU versions called flex and
bison, are more suited to this task than a regular expression.
Paul
------------------------------
Date: Wed, 25 Jul 2001 09:28:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular Expression Reduction
Message-Id: <jb4tltcat3f7nl598c5uuv4mrddkc7i0ic@4ax.com>
Paul Johnston wrote:
>You may find that lex and yacc, or the GNU versions called flex and
>bison, are more suited to this task than a regular expression.
Or the perl module Parse::RecDescent. I'm not really sure it can handle
this particular grammar, though...
--
Bart.
------------------------------
Date: Wed, 25 Jul 2001 09:35:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular Expression Reduction
Message-Id: <8e4tlt4l5675toa1k4icnljg62r9rhkoq9@4ax.com>
Moonshiner wrote:
> Here is how it is written:
>(posting has messed with the linefeeds and such but hopefully you can
>figure out what I mean.;))
>
>$range_definition = qq/(?:$numeric_literal|$name$ows$unary_adding_operator$ows$number|$nm_att|$integer|[+-]?\\d+|$r_paren)$ows$double_dot$ows(?:$numeric_literal|$attribute|$integer|$name$ows$unary_adding_operator$ows$number|$name|[+-]?\\d+|$l_paren$ows$anything$r_paren)/;
>
>where
>$numeric_literal = qq/$based_literal|$decimal_literal/;
>$based_literal = qq/[#](?:$letter_or_digit|$underscore$letter_or_digit)+[#]/;
>$decimal_literal = qq/(?:[+-]?\\d[(?:$underscore\\d|\\d)]*?$dot\\d[(?:$underscore\\d|\\d]*?(?:$exponent)?)\\b/;
>$name = qq/\\b(?:$letter\\w*)\\b/;
>$letter = qq/[a-zA-Z]/;
>$ows = qq/\\s*/; # optional white space
>$unary_adding_operator = qq/(?:$plus_sign|$minus_sign)/;
>$number = qq/\\d+/;
>$nm_att = qq/(?:$name)?(?:$appos(?:$name)?(?:$ows$l_paren$anything$r_paren)?)?/;
>$integer = qq/(?<![_\\d\.a-zA-Z])[+-]?\\d+(?:$underscore\\d+|\\d+)?(?![\\d\.a-zA-Z_#])/;
>$r_paren = qq/\\)/;
>$l_paren = qq/\\(/;
>$anything = qq/.*/;
>
>Needless to say - the regex created for $range_definition gets rather
>long (755 characters including parenthesis and other punctuation. I
>would include it but I am having to use a (ugh)Windows box to write
>this and is a totally separate machine. The code is running on Sun
>Unix boxes.
Why are you using qq//, not qr//? And why do you want to interpolate the
data there and then? Perl can handle
/a($re)b/o
very well, just like that. For example:
$letter = q/[a-zA-Z]/;
$name = qr/\b(?:$letter\w*)\b/;
print $name;
-->
(?-xism:\b(?:[a-zA-Z]\w*)\b)
Note that the syntax in qr// is the same as for normal regexes. No
double blackslashes, or other tricks, necessary.
--
Bart.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1374
***************************************