[9860] in Perl-Users-Digest
Perl-Users Digest, Issue: 3453 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 15 12:07:14 1998
Date: Sat, 15 Aug 98 09:00:17 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 15 Aug 1998 Volume: 8 Number: 3453
Today's topics:
create a user account + shadow pass on REDHAT Unix with <ccadic@cadic.com>
Enhance Warning meaning, possibly? <sneaker@sneex.fccj.org>
Re: Enhance Warning meaning, possibly? <rick.delaney@shaw.wave.ca>
Re: Enhance Warning meaning, possibly? <jdf@pobox.com>
Re: File updating question (M.J.T. Guy)
file upload problem <xuchu@iscs.nus.edu.sg>
Re: file upload problem <rick.delaney@shaw.wave.ca>
Re: How to read multiline variable? (M.J.T. Guy)
Re: Integration of perl into C (Lawrence Kirby)
Link to a CGI script in a CGI script <knarf@dvd-dream.dyn.ml.org>
Re: msgrcv not blocking (M.J.T. Guy)
Re: OLE Perl Excel brenda_lowe@my-dejanews.com
Re: OLE Perl Excel brenda_lowe@my-dejanews.com
Re: OLE Perl Excel <rick.delaney@shaw.wave.ca>
Re: perl to html <rick.delaney@shaw.wave.ca>
perl5 large integer conversion bug <jaakko@hyvatti.iki.fi>
Print Buffer order problem (Peter J. Elfman)
Re: Print Buffer order problem <jdf@pobox.com>
Re: re first language <gimonca@mirage.skypoint.net>
Regular Expression (AND search) (Marc-A. Woog)
Re: Regular Expression (AND search) <dcameron@bcs.org.uk>
Re: What is the purpose of Perl (Bart Schuller)
Re: X-file (?=...), case postponed. (Patrick Timmins)
Re: X-file (?=...), case postponed. <rick.delaney@shaw.wave.ca>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 15 Aug 1998 15:49:46 +0200
From: "cadic" <ccadic@cadic.com>
Subject: create a user account + shadow pass on REDHAT Unix with perl ?? help
Message-Id: <6r43bo$g1n$1@platane.wanadoo.fr>
I'm looking for a perl script to create a user account on my REdhat Linux.
It has to do shadow passwords.
I would like to offer to my www visitors the way to create an adduser user
account from a www html form working with a perl cgi.
The script would adduser and passwd the information.
Help .....
Please answer to : ccadic@cadic.com
Thanks so much.
I should be able to offer a POP3 accoutn and a small www space to someone
helping me.
A+
------------------------------
Date: Sat, 15 Aug 1998 09:36:24 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Enhance Warning meaning, possibly?
Message-Id: <35D58ED8.731F5713@sneex.fccj.org>
Under 5.004_04 (Linux 2.0.34 RedHat 5.1) -
This is a warning message, which could stand some more
clarity in meaning, appeared during a minor script run:
Value of <HANDLE> construct can be "0"; test with defined() at
LastNamesBOLD.pl
line 65535 (#1)
(W) In a conditional expression, you used <HANDLE>, <*> (glob),
each(),
or readdir() as a boolean value. Each of these constructs can
return a
value of "0"; that would make the conditional expression false,
which is
probably not what you intended. When using these constructs in
conditional
expressions, test their values with the defined operator.
I got the above with this line:
while($inpData = <INPUTFILE>)
The warning disappeared when I changed it to this:
while($inpData = "".<INPUTFILE>)
However, in the meantime, I thought the warning was
telling me to actually do this:
while($inpData = define(<INPUTFILE>))
Which only returned 1's (one for each line read.)
This is not the behavior I wanted either.
Maybe an example, like my three above, would clarify better?
PS - I don't have 65,535 lines in the script either,
which is also a little misleading. :]
PPS - The documentation in Perl is outstanding, so please
do not take this as a slight of the docs, just a suggestion
for improvement.
Thank you for your time :]
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: Sat, 15 Aug 1998 14:16:47 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Enhance Warning meaning, possibly?
Message-Id: <35D599BE.FD80FA55@shaw.wave.ca>
[posted and mailed]
Bill 'Sneex' Jones wrote:
>
> Under 5.004_04 (Linux 2.0.34 RedHat 5.1) -
>
> This is a warning message, which could stand some more
> clarity in meaning, appeared during a minor script run:
>
> Value of <HANDLE> construct can be "0"; test with defined() at
> LastNamesBOLD.pl
> line 65535 (#1)
>
> I got the above with this line:
> while($inpData = <INPUTFILE>)
>
Because if <INPUTFILE> returns zero, the assignment will be false and
you will miss out on a piece of data.
> The warning disappeared when I changed it to this:
> while($inpData = "".<INPUTFILE>)
>
That gets rid of the warning but will still be false if <INPUTFILE>
returns zero.
> However, in the meantime, I thought the warning was
> telling me to actually do this:
> while($inpData = define(<INPUTFILE>))
>
> Which only returned 1's (one for each line read.)
> This is not the behavior I wanted either.
>
Of course. The warning is telling you to use
while(defined($inpData = <INPUTFILE>)
which will be true until EOF.
> Maybe an example, like my three above, would clarify better?
>
I think I read here that this warning doesn't come up in 5.005 so a
patch is probably not necessary.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 15 Aug 1998 10:44:19 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Enhance Warning meaning, possibly?
Message-Id: <zpd66yi4.fsf@mailhost.panix.com>
Rick Delaney <rick.delaney@shaw.wave.ca> writes:
> Bill 'Sneex' Jones wrote:
> > Value of <HANDLE> construct can be "0"; test with defined() at
> > LastNamesBOLD.pl
> > line 65535 (#1)
> >
> > I got the above with this line:
> > while($inpData = <INPUTFILE>)
> >
>
> Because if <INPUTFILE> returns zero, the assignment will be false and
> you will miss out on a piece of data.
More specifically, if the *last line* of INPUTFILE is 0 without a
newline, you'll never see it. Any other line that contains only a 0
should be fine (since $inpData will contain "0\n", which is a true
value).
But, sure enough, 5.005 knows about this pathological case, and
returns a last-line 0 just fine.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: 15 Aug 1998 13:39:23 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: File updating question
Message-Id: <6r432b$29d$1@pegasus.csx.cam.ac.uk>
Ketan Patel <ketanp@NOSPAMxwebdesign.com> wrote:
>
>So how do I prevent B from opening the file before A is completely done
>with it? Am I supposed to be using 'flock' is this case?
It's not a matter of stopping B from opening the file. Rather it's
a question of stopping B from updating the file. So use a
non-destructive form of open:
open FH, "+<$fileB" or die "Couldn't open: $!\n";
flock ...
Then use seek() and truncate() as needed.
Mike Guy
------------------------------
Date: 15 Aug 1998 14:52:06 GMT
From: wings <xuchu@iscs.nus.edu.sg>
Subject: file upload problem
Message-Id: <6r47am$gji7@id4.nus.edu.sg>
i'm using CGI.pm to handle file uploads. however, when i tried to save
the uploaded file into a temp file (on unix), it always told me the temp
file cant be written. i've had written priviledge set for the directory..
where am i wrong?
--
wings
------
World is a book, those dont travel read only one page.
Email: xwings@usa.net, xuchu@iscs.nus.edu.sg
ICQ UIN: 1440319
http://gump.iscs.nus.edu.sg
------------------------------
Date: Sat, 15 Aug 1998 15:19:34 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: file upload problem
Message-Id: <35D5A87C.9736F2A@shaw.wave.ca>
[posted and mailed]
wings wrote:
>
> i'm using CGI.pm to handle file uploads. however, when i tried to save
> the uploaded file into a temp file (on unix), it always told me the
> temp file cant be written.
I'll bet it didn't say so in those words. Let's see the actual error
message(s).
> i've had written priviledge set for the directory..
How about on the file?
> where am i wrong?
In not posting the offending code and the error messages it produces.
(Please note that 'offending code' does not mean the entire script).
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 15 Aug 1998 13:07:36 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to read multiline variable?
Message-Id: <6r416o$165$1@pegasus.csx.cam.ac.uk>
Ken Williams <tekkin@hotmail.com> wrote:
>
>#!/usr/bin/perl
>$Output = `/bin/ls -l'`;
>
> while (<$Output>)
>{
> (Do something with single line)
> print $Output;
>}
>
>How would I accomplish the above? I can't use the while the way it is there,
>because $Output isn't a file handle, its a variable. I simply want to read
>the output of /bin/ls($Ouput) one line at a time so I can do something with it
>first.
Put the results of the /bin/ls into an array. Then use shift() to peel
off each line:
#!/usr/bin/perl
my @Output = `/bin/ls -l'`;
while (my $line = shift @Output)
{
(Do something with single line)
print $line;
}
But you probably don't really want to call /bin/ls like that at all.
You can avoid using external programs, with all their portability and
performance issues. Use Perl's opendir/readdir/closedir to get the
list of files, and stat() (or lstat() ) to get the required file details.
Mike Guy
------------------------------
Date: Sat, 15 Aug 98 14:27:22 GMT
From: fred@genesis.demon.co.uk (Lawrence Kirby)
Subject: Re: Integration of perl into C
Message-Id: <903191242snz@genesis.demon.co.uk>
In article <6r29ir$gs7$1@news-1.news.gte.net>
Harry_Andree@smtplink.mssm.edu "Harry Andree" writes:
>I'm trying to speed up some of the perl functions by recoding it in C.
>I use the perl.h library.
>I retrieve an HV pointer with the perl_get_hv function
>Then I retrieve an sv by calling the hv_iterinit function
>and hv_iternextsv. The latter call works fine but if I
>put the function in a subroutine I get a SEGV error
>and core dump: this is the code:
>
>char* totoken(char *var) {
Function names beginning with to followed by a lowercase letter are reserved
for use by the implementation (notably in relation to <ctype.h>).
> char buffer[50];
> char str[5000];
> HV* hv = NULL;
> SV* sv = NULL;
> char *name = NULL;
> char *value = NULL;
> int maxkeys;
> int n, len, len1;
> strcpy(buffer, var);
This assumes that var pointer to a string of length 49 characters or less.
> hv = perl_get_hv(buffer, 1);
> tohash(hv);
> return str;
Here you are returning the address of an automatic variable. str will no
longer exist after this function has returned so this pointer is invalid
in the caller. Your options are:
1. Make str static
2. Allocate a buffer dynamically using malloc. It then becomes the
responsibility of the caller to free it.
3. Have the caller allocate the buffer and pass a pointer to it as another
argument. Your function can then write to this buffer. Consider as
an example standard library fucntion like fgets() that do this (you may
also want to pass a buffer size as they do).
Another problem is that you never actually write anything to the str array.
>}
>
>char* tohash(HV* hv) {
rename.
> char str[5000];
This is a completely independent variable to str in the totoken() function.
If you want to access that one here pass a pointer to it as an extra
argument and reference it through that.
> SV* sv = NULL;
> HE* he = NULL;
> char *name;
> char *value = NULL;
> int maxkeys;
> int n, len, len1;
> maxkeys = hv_iterinit(hv);
> strcpy(str , "<");
> len = 10;
> for (n=0;n<maxkeys;n++) {
> sv = hv_iternextsv(hv, &name, len);
> strcat(str, ":");
> strcat(str, ";");
> }
> strcat(str , ">");
Rather than using strcal lots of times you mignt consider moving through the
str array with a pointer.
> return str;
Again, you are returning a pointer to a locally defined automatic object
which can never do anything useful. Since the caller in this case
doesn't use the returned value it doesn't matter too much but you've
lost the data you write to str here.
>}
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
------------------------------
Date: Sat, 15 Aug 1998 16:21:55 +0200
From: Knarf <knarf@dvd-dream.dyn.ml.org>
Subject: Link to a CGI script in a CGI script
Message-Id: <35D59983.2FBBB4B@dvd-dream.dyn.ml.org>
Hi, this is my first time posting here, i'm french and spent a lot of
time reading this newsgroup.
I'm trying to write a script that produces links to different parts of a
database in an HTML document. CGI.pm allows me to get params from a
search form i've already made. Thus, i can read complex parameter values
including spaces, without "unwebify" my form results.
But how can i make a script react to an "unwebified" parameter ???
example:
I can read the output a a texfield called "thing_value" by doing this:
my $thing = param("thing_value");
chomp ($thing);
So if i typed 'foo foo foo' into my textfield, now $thing value is "foo
foo foo" (i hope so :-))
But now if i want to link to another script that can react to "foo foo
foo":
print "<a
href=$my_url/cgi-bin/another.cgi?react_param=$my_foo_foo>$thing</a>\n";
How can i set up $my_foo_foo? Is there any function (already included)
that could take a param from an HTML form without "unwebifying" it. This
could allow me to store it before "unwebification" and use it later in
another.cgi.
Any help, FAQ, url swould be great !!
Sorry if the question is lame. :-)
Knarf
------------------------------
Date: 15 Aug 1998 13:46:30 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: msgrcv not blocking
Message-Id: <6r43fm$2cg$1@pegasus.csx.cam.ac.uk>
<kstevens7@my-dejanews.com> wrote:
>msgrcv() is returning after a short delay (with errno = EINTR "Interrupted
>System Call") rather than blocking until a message arrives (as it should).
>I'm passing "0" as the flag which according to the msgrcv manpage means that
>it should block. I looked at the perl source code for do_msgrcv and it seems
>to be passing the flag through unmodified. Is there some wrapper which has a
>timeout for system calls? If there's a message in the queue, msgrcv behaves
>correctly.
Since the Perl msgrcv() is just a wrapper for the underlying C call, it
behaves in the same way. In particular, an interrupt causes it to
return EINTR as you observe. You'll need to put a loop round the
msgrcv() which retries if EINTR is received.
Mike Guy
------------------------------
Date: Sat, 15 Aug 1998 14:26:15 GMT
From: brenda_lowe@my-dejanews.com
Subject: Re: OLE Perl Excel
Message-Id: <6r45q6$564$1@nnrp1.dejanews.com>
In article <6r2drg$viu$1@nnrp1.dejanews.com>,
olivierh3964@my-dejanews.com wrote:
> I am trying to read the container of a cell instead of its value in Perl.
>
> To read its value I would do :
>
> my $Variable = $ex->Range("A1")->{Value};
>
<snip>
Hi, I need to write a perl script that will allow me to gather statistics on
Excel workbooks. I need things like number of worksheets, number of macros
(and retrieve them if possible), number of columns, number of rows, the field
types (particularily date formated fields) and other things that might lend
an aid in deciding how Y2K infected the workbook is.
Also, how does one find out the methods, properties and objects that the Excel
OLE interface supports?
Thanks in advance.
Brenda
brenda.lowe@usa.net
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sat, 15 Aug 1998 14:37:53 GMT
From: brenda_lowe@my-dejanews.com
Subject: Re: OLE Perl Excel
Message-Id: <6r46g1$5pl$1@nnrp1.dejanews.com>
In article <6r2drg$viu$1@nnrp1.dejanews.com>,
olivierh3964@my-dejanews.com wrote:
> I am trying to read the container of a cell instead of its value in Perl.
>
> To read its value I would do :
>
> my $Variable = $ex->Range("A1")->{Value};
>
<snip>
Hi, I too need to figure out how to examine Excel workbooks. Does anyone
have any perl code they'd be willing to sent or post that shows how to get
the number of worksheets, number of rows, columns, macros etc? I'd really
like to be able to read the macros and parse them for Y2K date seeds.
I'd also like to gather statistics or metrics on the workbook so I can keep
track of how much time a particular workbook with a given set of metrics took
to y2k renovate. To do all of this stuff, I need to know how to scan excel
spreadsheets (and access data bases later on) to extract the metrics.
Any help would be appreciated.
Thanks in advance,
Brenda
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sat, 15 Aug 1998 15:08:00 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: OLE Perl Excel
Message-Id: <35D5A5C6.713946CA@shaw.wave.ca>
brenda_lowe@my-dejanews.com wrote:
>
> Also, how does one find out the methods, properties and objects that
> the Excel OLE interface supports?
>
This stuff is found in the Excel documentation, specifically the Visual
Basic reference. You can use the Perl Win32::OLE module to access these
objects. How to do that is documented in the module, but the
definitions of any OLE objects that you want to use are necessarily in
the docs for the application to which they apply.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sat, 15 Aug 1998 14:21:58 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: perl to html
Message-Id: <35D59AFB.DE309B9D@shaw.wave.ca>
[posted and mailed]
godzila@freemail.nl wrote:
>
> I've wrote a perl scrip like this:"myperl.pl"
> more syslog.log |grep "Lansession up"
>
That is not a perl script, it is a unix command that presumably resides
in a shell script. Perhaps another group could help you better.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 15 Aug 1998 15:51:46 -0000
From: Jaakko Hyvdtti <jaakko@hyvatti.iki.fi>
Subject: perl5 large integer conversion bug
Message-Id: <6r4aqi$dst@mansikka.eunet.fi>
Just found out this:
Perl5 (at least versions 5.004_04 and 5.005_51 on Solaris 2.6 and
Linux 2.1) converts string variables containing >= 2^31 values to
negative integers if the variable has been used in numeric context
with & or | operators before conversion. Test case exhibiting the
bug:
$s = "3000000000";
print $s | 0, " $s ", $s, " ", $s/2, "\n";
Output from perl5, all versions I have tested this on:
3000000000 3000000000 3000000000 -647483648
Correct output from perl4.036:
3000000000 3000000000 3000000000 1500000000
Test cases that do *not* exhibit the problem:
$s = "3000000000";
print $s + 0, " $s ", $s, " ", $s/2, "\n"; # only | and & operators are buggy
$s = "3000000000";
$s = int($s); # adding this fixes the problem
print $s | 0, " $s ", $s, " ", $s/2, "\n";
$s = "3000000000";
print "$s ", $s, " ", $s/2, "\n"; # removing the | or & operator fixes it too
$s = 3000000000; # variables with numbers assigned to them have no problems
print $s | 0, " $s ", $s, " ", $s/2, "\n";
--
Jaakko.Hyvatti@iki.fi http://www.iki.fi/hyvatti/ +358 40 5011222
echo 'movl $36,%eax;int $128;movl $0,%ebx;movl $1,%eax;int $128'|as -o/bin/sync
--
Jaakko.Hyvatti@iki.fi http://www.iki.fi/hyvatti/ +358 40 5011222
echo 'movl $36,%eax;int $128;movl $0,%ebx;movl $1,%eax;int $128'|as -o/bin/sync
------------------------------
Date: Sat, 15 Aug 1998 14:45:24 GMT
From: elf@efga.org (Peter J. Elfman)
Subject: Print Buffer order problem
Message-Id: <35d5964f.15007158@news.mindspring.com>
Here is my code:
print "Content-type: text/html\n\n";
print "\n";
system(@args);
print "\n hello\n\n";
The output from the system command prints first, not second. Then the
Content-type header, then the hello. How do I make it all show up in
the proper order?
(I think the answer is on page 130 of the 2nd edition Programming Perl
book (llama), but I don't know how to put it into code :)
Get your free email and news posting account from Dragon*Con
http://www.dragoncon.net
------------------------------
Date: 15 Aug 1998 11:33:25 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: elf@efga.org (Peter J. Elfman)
Subject: Re: Print Buffer order problem
Message-Id: <u33exl0q.fsf@mailhost.panix.com>
elf@efga.org (Peter J. Elfman) writes:
> How do I make it all show up in the proper order?
>
> (I think the answer is on page 130 of the 2nd edition Programming Perl
> book (llama), but I don't know how to put it into code :)
You are right, sir. Now, did you not understand the part about how to
set it to a nonzero value?
$| = 1;
or
$|++;
are two common ways. Set the autoflush variable before any print
statements. Is it some other part that you didn't understand? If so,
post again.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: 15 Aug 1998 13:14:17 GMT
From: Charles Gimon <gimonca@mirage.skypoint.net>
Subject: Re: re first language
Message-Id: <6r41j9$1u7$1@shadow.skypoint.net>
On Thu, 06 Aug 1998 16:48:50 -0500, ray <ralba@distorted.net> wrote:
>My first language was basic about 10 years ago. After coding for a
>couple of years in that language I decided that perhaps programming was
>not for me. I completely dropped the idea of programming until about
>three years ago when the Internet came about. Now I am trying
>desperately to understand Perl. For the most part it reads simple,
>however, I sometimes find it difficult to get what I want from it due to
>my lack of programming experience. And since I am self teaching myself,
>I have no one to correct my mistakes.
>
>Do you think at this stage of the game, that I should perhaps
>investigate learning assembly to assist with my understanding of Perl, C
>and other languages?
>
Consider getting the O'Reilly 'sed & awk' book. You can give yourself
a fairly painless foundation in regular expressions, plus you'll
learn to use two little utilities that come standard with most flavors
of Unix. You can get free ports of these that will run from the
DOS command line, too. The syntax is very similar to (but not exactly
the same as) perl. You can write very useful small scripts in awk,
then apply your experience to larger projects in perl.
--
Wild new Ubik salad dressing, not | gimonca@skypoint.com
Italian, not French, but an entirely | Minneapolis MN USA
new and different taste treat that's | http://www.skypoint.com/~gimonca
waking up the world! | A lean, mean meme machine.
------------------------------
Date: Sat, 15 Aug 1998 14:25:53 GMT
From: mwoog@pobox.ch (Marc-A. Woog)
Subject: Regular Expression (AND search)
Message-Id: <35d69a1a.778577@news.datacomm.ch>
Hi there,
I am new to this group and actually I am newbie to Perl. So please
forgive me, if my question is somewhere in the FAQ (where is it?) or
answered before.
I have the following optimization problem:
I want to do an "AND"-Search on lines from a file. E.g. the user input
is "petr comp" then every line should be checked for "petr" and
"comp": when both expressions can be found something should be done
with that line.
This is the current comparison algorithm:
...
# $searchexpression provided by user
@searchlist = split(/ /,$searchexpression);
$flag = 0;
# if $temp is not in line set $flag=1
foreach $temp (@searchlist) {
if ($line !~ /($temp)/i) { $flag = 1; }
}
# $flag is still 0 so do something
if ($flag == 0) {
#do something with $line
}
...
The problem is that with every extra word the routine takes longer (2
words -> line is checked twice and so forth).
Is there a more elegant and efficient way to accomplish the same
thing?
Thanks in advance,
Marc
--
Marc-A. Woog
mwoog@pobox.ch
http://www.geocities.com/SouthBeach/Sands/2413
------------------------------
Date: 15 Aug 1998 15:11:52 GMT
From: "Duncan Cameron" <dcameron@bcs.org.uk>
Subject: Re: Regular Expression (AND search)
Message-Id: <01bdc85f$2571b860$593c63c3@dns.btinternet.com>
Hmm...
See the FAQ "How do I efficiently match many regular expressions at once?"
HTH
Duncan Cameron
Marc-A. Woog <mwoog@pobox.ch> wrote in article
<35d69a1a.778577@news.datacomm.ch>...
> Hi there,
>
> I am new to this group and actually I am newbie to Perl. So please
> forgive me, if my question is somewhere in the FAQ (where is it?) or
> answered before.
>
< remainder snipped>
------------------------------
Date: 15 Aug 1998 14:32:30 GMT
From: schuller+news@lunatech.com (Bart Schuller)
Subject: Re: What is the purpose of Perl
Message-Id: <903191549.550241@perla.rotterdam.luna.net>
In article <35D30FE9.1530@min.net>, John Porter <jdporter@min.net> wrote:
>for $him ( @crowd ) {
> unless ( defined $him->{'sin'} ) { # yes, you better quote it!
> $him->throw( $stone[0] );
To avoid the picking up of thrown stones by the crowd after this loop, I
recommend
$him->throw( shift @stone );
> last;
> }
>}
Presumably we now create scalar(@crowd) Threads and and wrap @stone in
an object with proper locking.
--
The idea is that the first face shown to people is one they can readily
accept - a more traditional logo. The lunacy element is only revealed
subsequently, via the LunaDude. [excerpted from the Lunatech Identity Manual]
------------------------------
Date: Sat, 15 Aug 1998 04:52:57 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: X-file (?=...), case postponed.
Message-Id: <6r3479$uv5$1@nnrp1.dejanews.com>
In article <1ddq8gh.v883v81dpaqrqN@bay1-557.quincy.ziplink.net>,
rjk@coos.dartmouth.edu (Ronald J Kimball) wrote:
[snip]
> You really don't understand how a regex is applied. With the above
> example:
I really do Ronald. Again, you are not seeing the forest through your
'quibbling trees'. I'm sorry you're having such a tough time with the way
the regex engine is able to enforce rules of mathematical parenthetical
precedence while using only left to right processing in combination
with backtracking. But this is, indeed, the case. As you are about to
demonstrate for us:
>
> /(?=(.*))/
>
> Regex engine sees '(?=' [or compiled equivalent]
> Regex engine begins a positive lookahead assertion. Thus,
> anything matched while in the (?=) will not be saved to the
> potential $&.
> Regex engine sees '('
> Regex engine begins parenthesized subexpression #1. Anything
> matched while in the () will be saved to the potential $1.
> Regex engine sees '.*'
> Regex engine matches a whole bunch of characters. Potential $1
> now contains the string of characters. Potential $& still
> contains the null string.
> Regex engine sees ')'
> Regex engine ends parenthesized subexpression #1. The value
> of potential $1 is now available as \1.
Stop right there Ronald (and thank you for illustrating my point).
Would you please tell me what is in the potential $1 right now if
the regex is applied to the string "Just another Perl Hacker" ?
I'll bet you a nickel that what is in the potential $1 is 'Just
another Perl Hacker', and not 'ust another Perl Hacker' ... Thanks!
So, in the original split expression context, we have a matching
substring in the delimiter (as you point out above) containing 'Just
another Perl Hacker'. According to the split docs, and I quote:
"If the PATTERN contains parentheses, additional array elements
are created from each matching substring in the delimiter."
since the perldocs show the matching substring in the delimiter being
thrown on to the array where it is encountered, and since we are
encountering it right off the bat, it should be thrown on to the
array. But instead it is discarded. This is curious, and illogical.
But please continue with your analysis:
> Regex engine sees ')'
> Regex engine ends positive lookahead assertion.
> Regex engines sees end of regex
> Regex engine has successfully matched regex. The value of
> potential $1 is assigned to $1. The value of potential $&
> is assigned to $&.
>
So how does $1 now magically become 'ust another Perl Hacker' instead of
'Just another Perl Hacker' ? Answer: It doesn't ! For some curious, illogical
and undocumented reason, Perl throws it out! So what you're left with is
what should be the second element as the first element (the 'J' that is
generated from the actual splitting on null, which, as Ronald documented
above, occurs after the capture of 'Just another Perl Hacker' in $1).
Ronald and Abigail, however, persist on saying that all this curious,
illogical and undocumented behaviour is, in fact, logical and documented
behavior.
> It's not illogical. Since it is difficult to understand, it should be
> documented better.
See! I told you so. Well, Ronald is starting to crack a bit on the documented
part of it, but Abigail is still pushing it hard. Although I haven't heard
from her lately, so maybe she's cracking on this by now as well!
They'll all come to their senses soon enough, I'm sure! :)
Patrick Timmins
U. Nebraska Medical Center
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sat, 15 Aug 1998 14:52:29 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: X-file (?=...), case postponed.
Message-Id: <35D5A203.BC2852D5@shaw.wave.ca>
[posted and mailed]
Patrick Timmins wrote:
>
> In article <1ddq8gh.v883v81dpaqrqN@bay1-557.quincy.ziplink.net>,
> rjk@coos.dartmouth.edu (Ronald J Kimball) wrote:
> [snip]
> > You really don't understand how a regex is applied. With the above
> > example:
> >
> > /(?=(.*))/
> >
The part that is left out before this elegant explanation is
Regex sees ''
Regex matches the null string at the first possible place.
The part you fail to understand is that the first possible place is
*between* the 'J' and the 'u'. This is a special case with split that
only applies to patterns that match the null string.
This is not the case with m/(?=(.*))/g, for example, where the first
possible match would be befor the 'J'.
> > Regex engine sees '(?=' [or compiled equivalent]
> > Regex engine begins a positive lookahead assertion. Thus,
> > anything matched while in the (?=) will not be saved to the
> > potential $&.
> > Regex engine sees '('
> > Regex engine begins parenthesized subexpression #1. Anything
> > matched while in the () will be saved to the potential $1.
> > Regex engine sees '.*'
> > Regex engine matches a whole bunch of characters. Potential $1
> > now contains the string of characters. Potential $& still
> > contains the null string.
> > Regex engine sees ')'
> > Regex engine ends parenthesized subexpression #1. The value
> > of potential $1 is now available as \1.
>
> Stop right there Ronald (and thank you for illustrating my point).
> Would you please tell me what is in the potential $1 right now if
> the regex is applied to the string "Just another Perl Hacker" ?
> I'll bet you a nickel that what is in the potential $1 is 'Just
> another Perl Hacker', and not 'ust another Perl Hacker' ... Thanks!
>
You just lost yourself a nickel.
> So, in the original split expression context, we have a matching
> substring in the delimiter (as you point out above) containing 'Just
> another Perl Hacker'. According to the split docs, and I quote:
>
No, containing 'ust another Perl Hacker'. You cannot look ahead from
behind the 'J' and expect the 'J' to be there.
> "If the PATTERN contains parentheses, additional array elements
> are created from each matching substring in the delimiter."
>
> since the perldocs show the matching substring in the delimiter being
> thrown on to the array where it is encountered, and since we are
> encountering it right off the bat, it should be thrown on to the
> array. But instead it is discarded. This is curious, and illogical.
Nothing is being thrown out. The first delimiter encountered is
"" . "ust another Perl Hacker"
I have added the "" to represent the place between the 'J' and the 'u'.
Split returns the elements in the order (string, delimiter, string,
delimiter, ...) which is in the order that they were encountered.
The first string in this example is 'J' and the first delimiter is 'ust
another Perl Hacker'. Then 'u' and 'st another Perl Hacker'.
Please get off this craxy mathematical parenthetical precedence kick.
It is completely at odds with left to right and backtracking.
Hopefully _this_ post will get through to the moderated group.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3453
**************************************