[15506] in Perl-Users-Digest
Perl-Users Digest, Issue: 2916 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 1 18:05:28 2000
Date: Mon, 1 May 2000 15:05:17 -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: <957218716-v9-i2916@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 1 May 2000 Volume: 9 Number: 2916
Today's topics:
Re: [IMPORTANT] Content-type to download an image! (Craig Berry)
Re: a clue, a hint, a slap in the face would be nice <lr@hpl.hp.com>
Re: a clue, a hint, a slap in the face would be nice <you.will.always.find.him.in.the.kitchen@parties>
Re: a clue, a hint, a slap in the face would be nice <Jonathan.L.Ericson@jpl.nasa.gov>
Authentication scripts etc <damon@shocking-pink.com>
Re: Authentication scripts etc <tony_curtis32@yahoo.com>
Re: Basic Exporter question (Stuart Kendrick)
Re: Basic Exporter question <bmb@ginger.libs.uga.edu>
Re: Basic Exporter question <tony_curtis32@yahoo.com>
Re: Basic Exporter question <uri@sysarch.com>
Re: convert to tab delimited file. <mcahren@att.net>
Re: convert to tab delimited file. <makarand_kulkarni@My-Deja.com>
Re: Documenting Cron <bernie@nationwide.net>
Re: Help: bol regexp in split string <occitan@esperanto.org>
Re: Help: bol regexp in split string <rootbeer@redcat.com>
Re: Help: bol regexp in split string (Bart Lateur)
Re: HOW CAN I TELL... (OT) <lr@hpl.hp.com>
Re: How do I detect the presence of a network? <rootbeer@redcat.com>
Re: How do I detect the presence of a network? <mjcarman@home.com>
Re: how to count number of characters in a string? (Craig Berry)
Re: How to know someone exit? <rootbeer@redcat.com>
Re: How to test perl CGI scripts on my computer first? <chrisbragg31@yahoo.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 01 May 2000 19:53:54 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: [IMPORTANT] Content-type to download an image!
Message-Id: <sgro6i38oog20@corp.supernews.com>
Makau Divangamene (makau@multimania.com) wrote:
: PS : I didn't use your suggested read() function since I don't know how
: to use it.
Never a good excuse with Perl, as you have the full docs right there on
your drive. 'perldoc -f read'.
: Also it seems impossible to use "die" to send and html error
: message (the directive 'or die "Content-type:
: text/html\n\n<HTML><BODY>Error</BODY></HTML>"' can't seem to work)
perldoc CGI::Carp
See in particular the section concering 'fatalsToBrowser'; it does exactly
what you're looking for.
Two good general rules for Perl:
1) Use the online doc intelligently; it's well written and comprehensive.
2) If you're trying to do something that seems like it should be a pretty
common task (like, e.g., making errors appear in the browser), odds
are there's a module that does it, either included with your Perl
distribution or on CPAN. Avoid reinventing wheels.
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: Mon, 1 May 2000 11:31:19 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: a clue, a hint, a slap in the face would be nice
Message-Id: <MPG.13776d49cea0cb098a9bf@nntp.hpl.hp.com>
[A more descriptive Subject would be nice. Many people will simply
ignore this cutesiness.]
In article <8eka0g$c3h$1@nnrp1.deja.com> on Mon, 01 May 2000 16:06:08
GMT, glm2@my-deja.com <glm2@my-deja.com> says...
> I have a two directories, one a backup of the other. Unfortunately some
> files in the backup are not in the main directory.
>
> There is no sort either by last updated or by name that can be used to
> pull out the files.
>
> I did a ls > tmp in each directory and then a diff tmp1 tmp2 > tmp_diff.
Ugh. Perl has the tools to do this internally, quickly and cleanly.
> I'll like to write a script that pulls out the lines from tmp_diff but
> have come to end of my scripting skills.
Some of the lines in your tmp_diff will be diff line numbers, etc.
Let's forget about it.
The following INCOMPLETELY TESTED code prints a list of files that are
in one directory ($dir2) but not in the other ($dir1). To understand
the method, read perlfaq4: "How can I tell whether a list or array
contains a certain element?" Then adapt it to your needs.
#!/usr/bin/perl -w
use strict;
my $dir1 = '/whereever/it/is1';
my $dir2 = '/whereever/it/is2';
my %dirs;
opendir DIR, $dir1 or die "Couldn't open '$dir1'. $!\n";
@dirs{(readdir DIR)} = ();
opendir DIR, $dir2 or die "Couldn't open '$dir2'. $!\n";
print map "$_\n" => grep !exists $dirs{$_} => readdir DIR;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 2 May 2000 07:53:35 +1200
From: "Tintin" <you.will.always.find.him.in.the.kitchen@parties>
Subject: Re: a clue, a hint, a slap in the face would be nice
Message-Id: <957210753.333034@shelley.paradise.net.nz>
<glm2@my-deja.com> wrote in message news:8eka0g$c3h$1@nnrp1.deja.com...
> I have a two directories, one a backup of the other. Unfortunately some
> files in the backup are not in the main directory.
>
> There is no sort either by last updated or by name that can be used to
> pull out the files.
>
> I did a ls > tmp in each directory and then a diff tmp1 tmp2 > tmp_diff.
>
> I'll like to write a script that pulls out the lines from tmp_diff but
> have come to end of my scripting skills.
>
> The thinking is
>
> while (<>) {
>
> foreach (@ARGV){ #take each line of @ARGV
>
> print cp $_ new_dir/; # copy each file into new_dir
>
> }
> }
>
> It's not working. Duh!!!! If it was I wouldn't be posting this message.
Not a Perl answer, but depending on what Unix system you are on, see
man dircmp
------------------------------
Date: Mon, 01 May 2000 12:02:01 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: a clue, a hint, a slap in the face would be nice
Message-Id: <390DD4A9.AB94350C@jpl.nasa.gov>
glm2@my-deja.com wrote:
> I have a two directories, one a backup of the other. Unfortunately some
> files in the backup are not in the main directory.
>
> There is no sort either by last updated or by name that can be used to
> pull out the files.
>
> I did a ls > tmp in each directory and then a diff tmp1 tmp2 > tmp_diff.
In Perl, I would open a directory handle ('perldoc -f readdir'), glob
the directory ('perldoc -f glob') or use backticks (my @files = `ls`;).
That way you could get an array of filenames and avoid having to make
tmp files. At that point you can manipulate the arrays ('perldoc -f
intersection') and perlform (err... perform) operations with their
contents.
> I'll like to write a script that pulls out the lines from tmp_diff but
> have come to end of my scripting skills.
>
> The thinking is
#!/usr/bin/perl -w
use strict;
Unless you are writing a one-liner, let perl catch your mistakes and
typos.
> while (<>) {
Read perlop/'I/O Operators' to find out what this loop does.
> foreach (@ARGV){ #take each line of @ARGV
Actually @ARGV is the array of command line arguments. This loop is
almost certainly a conceptual error.
> print cp $_ new_dir/; # copy each file into new_dir
This line doesn't compile even with warnings turned off. If you want to
get better descriptions (and possible solutions) 'use diagnostics;' or
read perldiag. Perhaps you intended something like:
print `cp $_ new_dir/`;
Even then, I don't think this will do what you want. Here is a sample
output of diff on my system:
11a12
> tmp
It's easier just to do it all in perl as I suggest above. Also consider
using File::Copy.
> }
> }
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Mon, 1 May 2000 19:45:47 +0100
From: "Damon Goodyear" <damon@shocking-pink.com>
Subject: Authentication scripts etc
Message-Id: <957206796.7594.0.nnrp-12.9e983b90@news.demon.co.uk>
This is a lame question from someone who has spent the day looking for an
answer to an ill-defined question.
I'm looking for somewhere to start.
I want to be able to programmatically (ie using Perl) add users to an
.htaccess file. Does anybody have any idea whether this has been done and
if so where I can get the source code?
Thanx
Damon
PS Just seen a posting from Randal Schwartz (not _the_ Randal Schwartz?
Gor... me mates will be well impressed. :-))
------------------------------
Date: 01 May 2000 13:55:21 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Authentication scripts etc
Message-Id: <87itwyksme.fsf@shleppie.uh.edu>
>> On Mon, 1 May 2000 19:45:47 +0100,
>> "Damon Goodyear" <damon@shocking-pink.com> said:
> This is a lame question from someone who has spent the
> day looking for an answer to an ill-defined question.
> I'm looking for somewhere to start.
> I want to be able to programmatically (ie using Perl)
> add users to an .htaccess file. Does anybody have any
> idea whether this has been done and if so where I can
> get the source code?
http://search.cpan.org/
HTTPD::UserAdmin
hth
t
------------------------------
Date: 1 May 2000 18:22:00 GMT
From: skendric@fhcrc.org (Stuart Kendrick)
Subject: Re: Basic Exporter question
Message-Id: <8eki08$m92$1@pony.fhcrc.org>
Hi Tony,
OK, I got it. (I learned that my choice of "Test.pm" was a poor one --
"Test.pm" already ships with PERL.)
Now I'm running into the reason I started putting "my" constructs
around my variable names.
I quite specifically don't want to use the @EXPORT_OK construct. My
real program -- not shown here -- defines a ton of variables which I
then want imported into other scripts. I don't want to be updating
this list of variables on "use Foo qw(x y z)" every time I add another
variable to my Foo.pm file.
So, I use the @EXPORT construct.
Works great.
But when I add "use strict" to Foo.pm, I see the error message
"requires explicit package name".
Now, I like being strict :)
How do I reconcile my desire to export a list of variables with my
desire to be strict?
uluc05{root}: cat test.pl
#!/opt/local/bin/perl
use Foo qw($colour);
print "$colour\n";
uluc05{root}: cat Foo.pm
package Foo;
use strict;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw($colour);
$colour = 'octarine';
1;
uluc05{root}: perl -w test.pl
Global symbol "@ISA" requires explicit package name at Foo.pm line 6.
Global symbol "@EXPORT" requires explicit package name at Foo.pm line
7.
Global symbol "$colour" requires explicit package name at Foo.pm line
9.
Compilation failed in require at test.pl line 3.
BEGIN failed--compilation aborted at test.pl line 3.
uluc05{root}:
--sk
Stuart Kendrick
FHCRC
------------------------------
Date: Mon, 1 May 2000 14:43:19 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Basic Exporter question
Message-Id: <Pine.A41.4.10.10005011439080.13002-100000@ginger.libs.uga.edu>
On 1 May 2000, Stuart Kendrick wrote:
> Hi Tony,
>
> OK, I got it. (I learned that my choice of "Test.pm" was a poor one --
> "Test.pm" already ships with PERL.)
>
> Now I'm running into the reason I started putting "my" constructs
> around my variable names.
>
> I quite specifically don't want to use the @EXPORT_OK construct. My
> real program -- not shown here -- defines a ton of variables which I
> then want imported into other scripts. I don't want to be updating
> this list of variables on "use Foo qw(x y z)" every time I add another
> variable to my Foo.pm file.
>
> So, I use the @EXPORT construct.
>
> Works great.
>
> But when I add "use strict" to Foo.pm, I see the error message
> "requires explicit package name".
>
> Now, I like being strict :)
>
> How do I reconcile my desire to export a list of variables with my
> desire to be strict?
You want "use vars". See also `man perlmod` or `perldoc perlmod`; look
for "Exporter".
> uluc05{root}: cat test.pl
> #!/opt/local/bin/perl
> use Foo qw($colour);
> print "$colour\n";
... but you're not being strict here (no '-w' either). Sure, it's just a
test, but during development (and learning) is when they help you the
most.
--
Brad
------------------------------
Date: 01 May 2000 13:54:40 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Basic Exporter question
Message-Id: <87ln1uksnj.fsf@shleppie.uh.edu>
>> On 1 May 2000 18:22:00 GMT,
>> skendric@fhcrc.org (Stuart Kendrick) said:
> But when I add "use strict" to Foo.pm, I see the error
> message "requires explicit package name".
> uluc05{root}: cat Foo.pm
> package Foo;
> use strict;
> use Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw($colour);
> $colour = 'octarine';
> 1;
How come you chopped out the "use vars" line?
perldoc -f use
I think you'll find it helpful.
tony
------------------------------
Date: Mon, 01 May 2000 19:03:42 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Basic Exporter question
Message-Id: <x766syytwz.fsf@home.sysarch.com>
>>>>> "SK" == Stuart Kendrick <skendric@fhcrc.org> writes:
SK> I quite specifically don't want to use the @EXPORT_OK construct. My
SK> real program -- not shown here -- defines a ton of variables which I
SK> then want imported into other scripts. I don't want to be updating
SK> this list of variables on "use Foo qw(x y z)" every time I add another
SK> variable to my Foo.pm file.
first off, call it a module and not a program. second, there are good
reasons not to use @EXPORT and why @EXPORT_OK is better. and you don't
have to have each importing program update all the var names each time
the list is changed. read the Exporter man page for the %EXPORT_TAGS
which supports that very thing. then you only import a single tag and
maintain those lists in the imported module.
SK> So, I use the @EXPORT construct.
SK> Works great.
and you have to worry about collisions in name space if someone doesn't
want all those names. export_ok is much safer. in fact other than for
legacy code, there is almost no reason to ever use @EXPORT as @EXPORT_OK
can do all the same work and is safer
SK> uluc05{root}: cat Foo.pm
SK> package Foo;
SK> use strict;
SK> use Exporter;
SK> @ISA = qw(Exporter);
SK> @EXPORT = qw($colour);
SK> $colour = 'octarine';
SK> Global symbol "@ISA" requires explicit package name at Foo.pm line 6.
SK> Global symbol "@EXPORT" requires explicit package name at Foo.pm line
SK> 7.
SK> Global symbol "$colour" requires explicit package name at Foo.pm line
SK> 9.
so now that those vars are not my'ed, where are they being declared so
strict won't yell at you? you need to do this:
use vars qw( @ISA @EXPORT $colour ) ;
and even simpler is to do:
use base qw( Exporter ) ;
use vars qw( @EXPORT $colour ) ;
no need to load Exporterr, or declare or assign to @ISA, the base module
does it for you.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 1 May 2000 14:18:44 -0500
From: "Jeff McAhren" <mcahren@att.net>
Subject: Re: convert to tab delimited file.
Message-Id: <e8zMTF6s$GA.328@cppssbbsa04>
This could be written in VB in a snap.
I don't know of anything available that already does this, it does not sound
like a common task.
Gary Artim wrote in message <390DC127.345CB831@dkstat.com>...
>I'm writing some html/cgi/perl code and wonder if anyone has found a
>filter program that converts native EXCEL files to tab delimited text
>files. Any info would be greatly appreciated. I do know that EXCEL
>provides this save option, I'm just looking for a software tool to do
>this.
>
>
>Thanks,
>
>
>Gary (gary@dkstat.com)
>
------------------------------
Date: Mon, 01 May 2000 13:02:09 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: convert to tab delimited file.
Message-Id: <390DE2C1.55037B21@My-Deja.com>
> I'm writing some html/cgi/perl code and wonder if anyone has found a
> filter program that converts native EXCEL files to tab delimited text
> files. Any info would be greatly appreciated. I do know that EXCEL
> provides this save option, I'm just looking for a software tool to do
> this.
>
use OLE.pm for perl ( win32).
Write your own programs to open the worksheets you need
and dump the data as you want it.
--
------------------------------
Date: Mon, 01 May 2000 16:17:05 -0500
From: Bernard Chandler <bernie@nationwide.net>
Subject: Re: Documenting Cron
Message-Id: <390DF451.82540825@nationwide.net>
Doug Thomas wrote:
> Hello,
>
> Does anyone have a program/script to document the crontab listing? For
> instance, it would show jobs which run on specific weekdays, days of the
> month, or every day. If not, I'll write one. An example follows:
>
> Monday
> -----------
> 8:00 AM My job 1
>
> Saturday
> ------------
> 2:30 AM My job 2
>
> Wednesday and Thursday
> ------------
> 1:00 AM and every 10 minutes My job 3
>
> Every day
> ------------
> 9:15 PM My job 4
>
> Any help is appreciated.
Are you saying that crontab -l is not pretty enough for you?
In hp/ux sam shows it pretty well in english.
Do it anyway. It can be fun.
What are you going to use? perl?
Do not forget that there can be several cron files.
Add to it the information on "at".
man cron
man at
Learning Perl
http://www.amazon.com/exec/obidos/ASIN/1565922840/webviator/002-7491712-0608224
--
Bernie Chandler
http://www.nationwide.net/~bernie
------------------------------
Date: Mon, 01 May 2000 20:05:46 GMT
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: Help: bol regexp in split string
Message-Id: <8eko2d$sml$1@nnrp1.deja.com>
In article
<Pine.GSO.4.10.10004281951050.21722-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
> On Fri, 28 Apr 2000 occitan@esperanto.org wrote:
>> Hi folks!
> Saluton, samlingvano!
Resaluton Tom!
>> My iPerl allows embedding bits of Perl in text documents by way of !{
>> ... }! anywhere, possibly spanning several lines, or whole lines
>> starting with !, as in:
>> text text !{ Perl code }! text
>> ! Perl code
>> text
>> !{ Perl
>> code
>> }!
>> text
>> The way this is implemented is by having the whole document in a
>> string and successively shaving of beginnings up to and including a
>> bit of Perl for transformation.
> Probably better to use Parse::RecDescent, or a well-crafted regular
> expression in s///, perhaps.
For efficiency reasons I don't like to draw in libraries that I won't be
using massively. And, though I know the CPAN module automates this,
even less ones that are not in the standard distribution. Concerning
s///, it would change too much and I'm not even sure how to use it here.
>> This is done by applying various functions, like this one (in the
>> bang style using !, the first 2 lines of regexp do 2 more things),
>> returning leading text, one or another bit of Perl and following text
>> on which it'll be applied in the next round:
>> $splitter = sub {
>> return $`, $1, $2 || $3 || $4, $'
>> if $_[0] =~ /
>> ^\# .* \n? |
>> !< ([\s\S]*?) >! |
>> !\{ ([\s\S]*?) \}! | !(\})! |
>> ^! (.*) \n?
>> /mx;
>> @_;
>> };
>> The problem occurs when the text contains a ! right after a bit of
>> Perl:
> Yes; it's pretty tough to get a hairy regular expression like that to
> be correct. You may be able to get something out of Jeffrey Friedl's
> excellent book, Mastering Regular Expressions. But I'd probably use
> Parse::RecDescent for this; that should make it pretty simple. (I
> hope!)
Laszlo Constantinescu had a better idea, which works well without major
code changes. The regexp (?!\A)^ will match all newlines, except the
fake one at the beginning of the string. So I look for a newline at the
end of the last match and depending on that, use this or simply ^ via a
variable interpolated into the regexp.
This also gave me the idea for another feature I had in mind (already
implemented in 0.53 to be released soon) on how to treat comments. :-)
>> On another topic, in this case, most of $1 thru $4 are not defined.
>> Is there an elegant way to rewrite this such that I can use perl -w?
> Check to see whether they're defined before you use them. :-)
> if (defined $2) { ... }
> Gxuu!
Ne, mi ne ^guas! My problem was
>> return $`, $1, $2 || $3 || $4, $'
>> if $_[0] =~ /.../;
and it seems real awkward to test all those (some styles even have more
submatches). All the more so, since definedness for the returned list
values get's tested by the caller of this sub. But -w doesn't care,
since for it this is already use of an undefined value. I'm considering
simply locally setting $^W, thereby making it clear everything is ok?
thanx kaj dankon!
--
Bring text-docs to life! Erwecke Textdokumente zum Leben!
http://beam.to/iPerl/
Vivigu tekstodokumentojn!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 1 May 2000 13:46:26 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Help: bol regexp in split string
Message-Id: <Pine.GSO.4.10.10005011336250.13677-100000@user2.teleport.com>
On Mon, 1 May 2000, Daniel Pfeiffer wrote:
> > Probably better to use Parse::RecDescent, or a well-crafted regular
> > expression in s///, perhaps.
>
> For efficiency reasons I don't like to draw in libraries that I won't be
> using massively. And, though I know the CPAN module automates this,
> even less ones that are not in the standard distribution.
Did you realize that you can use Parse::RecDescent to produce a parser
which (as nearly as I can tell without trying it) shoudn't require
Parse::RecDescent to be installed at run time?
> My problem was
>
> >> return $`, $1, $2 || $3 || $4, $'
> >> if $_[0] =~ /.../;
>
> and it seems real awkward to test all those (some styles even have more
> submatches).
That's another reason why you may benefit from a better regular
expression, or Parse::RecDescent.
> I'm considering simply locally setting $^W, thereby making it clear
> everything is ok?
I wouldn't do that; you'd be throwing away all possible warnings to
disable just one.
You may want something like this:
my $fred = $1 || '';
To be sure, that effectively replaces any false value with the empty
string. If that part of your pattern could match '0', you'll probably want
to only replace defined values:
my $fred = defined($1) ? $1 : '';
Of course, you'd choose a more-descriptive name than $fred for your
variable. And, if you have a long list of these variables, you can
efficiently do this transformation with a map.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 01 May 2000 21:37:29 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Help: bol regexp in split string
Message-Id: <390df2c3.2854891@news.skynet.be>
occitan@esperanto.org wrote:
>My iPerl allows embedding bits of Perl in text documents by way of !{
>... }! anywhere, possibly spanning several lines, or whole lines
>starting with !, as in:
>
>text text !{ Perl code }! text
>! Perl code
>text
>!{ Perl
>code
>}!
>text
>
>The way this is implemented is by having the whole document in a string
>and successively shaving of beginnings up to and including a bit of Perl
>for transformation. This is done by applying various functions, like
>this one (in the bang style using !, the first 2 lines of regexp do 2
>more things), returning leading text, one or another bit of Perl and
>following text on which it'll be applied in the next round:
>
> $splitter = sub {
> return $`, $1, $2 || $3 || $4, $'
> if $_[0] =~ /
> ^\# .* \n? |
> !< ([\s\S]*?) >! |
> !\{ ([\s\S]*?) \}! | !(\})! |
> ^! (.*) \n?
> /mx;
> @_;
> };
You're using the deprecated variables $` and $'. You do realize that
these will slow every (other) regex down, because of this one function?
Otherwise, an almost identical functionality can be gotten by doing:
my @match;
(my $pre, @match[0..3], $post) = split
^\# .* \n? |
!< ([\s\S]*?) >! |
!\{ ([\s\S]*?) \}! | !(\})! |
^! (.*) \n?
/mx, $_, 2;
It stores $1, $2, $3, $4 into @match[0..3], irrespective of which
parentheses actually actively captured anything. It doesn't combine them
yet, though.
>The problem occurs when the text contains a ! right after a bit of Perl:
>
>text text !{ Perl code }!! text
>
>The !, which is part of plain text, is now at the beginning of the
>rest-string, and thus at the beginning of line, making the last text be
>falsely recognized as Perl.
Hmmm... it sounds like you're using this function in a loop, applying it
to "$post" (AKA $'). That would mean that you'll have the same problem
with your /^\# .* \n?/x submatch.
One way to avoid all this, is to cheat: put one character (a space) in
front of the remainder of the string, if neither $1 nor $4 (the
subpatterns up till and including the end of the current line) are
defined. That means that you are not at the start of a line. Set a flag,
too. These subpatterns now cannot possibly match at the first line,
which is what you want. Remove that space again, according to the flag.
You could get rid of the question mark following the "\n", once you make
sure that the whole string is terminated by a newline.
>This should only be allowed to happen at
>the very beginning, or when several such lines succeed one another.
Oh. This makes me wonder: how do you allow for a normal line starting
with an exclamation mark?
--
Bart.
------------------------------
Date: Mon, 1 May 2000 14:50:06 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: HOW CAN I TELL... (OT)
Message-Id: <MPG.13779be6a11643f98a9c2@nntp.hpl.hp.com>
In article <dennis_marti-B8D5EA.01450829042000@news.starpower.net> on
Sat, 29 Apr 2000 01:45:08 -0400, Dennis Marti <dennis_marti@yahoo.com>
says...
> In article <MPG.1373a45461592b1198a9ae@nntp.hpl.hp.com>, Larry Rosler
> <lr@hpl.hp.com> wrote:
>
> > On 'most' operating systems (i.e., on the operating systems that run 90%
> > or more of the world's computers), the system imposes a mandatory lock
>
> Where did you find this statistic? I'm still looking, but, so far,
> haven't been able to verify it.
<URL:http://www.dcd.uscourts.gov/ms-findings2.pdf>
III. MICROSOFT'S POWER IN THE RELEVANT MARKET
...
A. Market Share
35. Microsoft possesses a dominant, persistent, and increasing share
of the worldwide market for Intel-compatible PC operating systems.
Every year for the last decade, Microsoft's share of the market for
Intel-compatible PC operating systems has stood above ninety percent.
For the last couple of years, the figure has been at least ninety-five
percent, and analysts project that the share will climb even higher over
the next few years. Even in Apple's Mac OS were included in the
relevant market, Microsoft's share would still stand well over eighty
percent.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 1 May 2000 12:20:17 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How do I detect the presence of a network?
Message-Id: <Pine.GSO.4.10.10005011218190.13677-100000@user2.teleport.com>
On Mon, 1 May 2000, Stephan Gross wrote:
> What I would like to do is have the Perl program check for
> connectivity to the LAN when it starts up. If the LAN/database is
> there, it will be used as a data source. If not, the accompanying
> local database will be used.
Probably you should simply try to connect to the database over the LAN and
simply fall back to the local one if that fails. It may be good to use an
eval block. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 01 May 2000 14:10:53 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: How do I detect the presence of a network?
Message-Id: <390DD6BD.D00D3BCE@home.com>
Stephan Gross wrote:
>
> I have an application that gets data from a database. The application
> will be distributed with the database. However, the most recent copy
> of the database is on the LAN.
>
> What I would like to do is have the Perl program check for
> connectivity to the LAN when it starts up. If the LAN/database is
> there, it will be used as a data source. If not, the accompanying
> local database will be used.
I'm not aware of any way to say "yes, I'm on the LAN," but you don't
really need to. Just try to open it there first. If unsuccessful, open
the local copy instead. e.g.
unless (open(DB, 'DB file from the LAN')) {
# Couldn't find DB on the LAN, use local copy instead
open(DB, 'local DB file')
or die "Couldn't even open the local DB: $!\n";
}
With the filenames (and error messages) adjusted appropriately.
-mjc
------------------------------
Date: Mon, 01 May 2000 19:55:34 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: how to count number of characters in a string?
Message-Id: <sgro9mn9oog89@corp.supernews.com>
steve (schan_ca@geocities.com) wrote:
: Length is what I am looking for.
It is indeed.
: I keep thinking this is Perl so there must
: be some regexp I have to do.
Just because Perl includes a really excellent lathe doesn't mean you
should use it to pound nails.
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: Mon, 1 May 2000 11:05:47 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to know someone exit?
Message-Id: <Pine.GSO.4.10.10005011104480.13677-100000@user2.teleport.com>
On Mon, 1 May 2000, sang wrote:
> How do i know someone had left my homepage(CGI)?
In short, you can't. But it sounds as if you want to search for the docs,
FAQs, and newsgroups about the web. The newsgroup
comp.infosystems.www.authoring.cgi may be useful. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 01 May 2000 22:41:10 +0200
From: Chris Bragg <chrisbragg31@yahoo.com>
Subject: Re: How to test perl CGI scripts on my computer first?
Message-Id: <390DEBE6.2271F487@yahoo.com>
I too needed to do this exact thing for a CMIS Perl class I'm taking. I
normally use Linux, but the class requires me to work under Windows too.
Anyway, I downloaded a program called Visual Perl Editor at:
http://kakoulidis.homepage.com/perl.html
In order for this all to work correctly, you will also need to download
and install the Win32 Apache web server, which can be had at:
http://www.apache.org/dist/binaries/win32/
The program is shareware, and supposedly has some functionality removed
until you register it for $29.00, but I haven't found anything I
couldn't do with it yet.
Good luck to you.
Chris
Ryan & Treena Carrier wrote:
>
> I'm trying to figure out how to set my computer up so I can write some CGI
> scripts in Perl and test them on my computer before posting them to my
> internet web server.
>
> I've tried setting up Personal Web Server (I'm running Windows 98) but my
> computer locks up when trying to start the Transaction Server, so I had to
> uninstall it.
>
> HELP!
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 2916
**************************************