[24770] in Perl-Users-Digest
Perl-Users Digest, Issue: 6923 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 27 21:06:04 2004
Date: Fri, 27 Aug 2004 18:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 27 Aug 2004 Volume: 10 Number: 6923
Today's topics:
Execute Windows program from Perl script (??) (Tony McGuire)
Re: Execute Windows program from Perl script (??) <nobull@mail.com>
Re: exit(), die, ?? <mritty@gmail.com>
How do you lock a file BEFORE changes are made? (J. Romano)
Re: How do you lock a file BEFORE changes are made? <dwall@fastmail.fm>
Re: How do you lock a file BEFORE changes are made? <noreply@gunnar.cc>
how many days ago is 2003-07-20 ? (Marcus)
Re: how many days ago is 2003-07-20 ? <noreply@gunnar.cc>
Re: how many days ago is 2003-07-20 ? <zebee@zip.com.au>
hv_iterinit has side effects - who cares about PL theor (Ozgun Erdogan)
Re: Larry Wall & Cults <snail@objmedia.demon.co.uk>
Re: Larry Wall & Cults (John Doherty)
Re: matching chunks of data with a regular expression <nobull@mail.com>
Re: Object Oriented programs, Perl and others <uri.guttman@fmr.com>
Re: Object Oriented programs, Perl and others (Anno Siegel)
Re: Own module needs loaded module from main script <noreply@gunnar.cc>
Re: performance surprise -- why? (Anno Siegel)
Re: performance surprise -- why? <uri.guttman@fmr.com>
Re: performance surprise -- why? <abigail@abigail.nl>
Re: performance surprise -- why? <abigail@abigail.nl>
Re: subroutines with XML (Anno Siegel)
Re: Xah Lee's Unixism <bcaligari@nospam.fireforged.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Aug 2004 13:48:21 -0700
From: tony@paradoxcommunity.com (Tony McGuire)
Subject: Execute Windows program from Perl script (??)
Message-Id: <f896a829.0408271248.63beaeaf@posting.google.com>
'Server' is win2k.
I've looked at exec() as well as system().
When I exec("dir"); I get an error log entry that includes the start
of the dir command response. So I *might* be able to figure it out
from there, but so far no luck. I've read several posts as well as
articles about exec() as well as system(), but haven't had any luck.
What I want is to launch a (Windows) program from a perl script and
for the perl script to continue on. No response from the external
program.
Also, the actual program I wish to execute is in c:\program
files\etc\etc.exe
When I try to exec() or system() it, it chokes at the first space
(after 'program') and reports "'C:Program' is not recognized as an
internal or external command." in the error log.
Does anyone have info on how to (whether I can) get perl to execute an
external program and continue on?
Any help appreciated.
------------------------------
Date: Fri, 27 Aug 2004 22:36:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <cgo9ht$3a0$1@slavica.ukpost.com>
Tony McGuire wrote:
> 'Server' is win2k.
>
> I've looked at exec() as well as system().
>
> When I exec("dir"); I get an error log entry that includes the start
> of the dir command response. So I *might* be able to figure it out
> from there, but so far no luck. I've read several posts as well as
> articles about exec() as well as system(), but haven't had any luck.
>
> What I want is to launch a (Windows) program from a perl script and
> for the perl script to continue on. No response from the external
> program.
>
> Also, the actual program I wish to execute is in c:\program
> files\etc\etc.exe
>
> When I try to exec() or system() it, it chokes at the first space
> (after 'program') and reports "'C:Program' is not recognized as an
> internal or external command." in the error log.
>
> Does anyone have info on how to (whether I can) get perl to execute an
> external program and continue on?
This is not a question about Perl, it is a question about the host
operating system's (in this case Window's) command line interpreter to
which system() give you access.
You enclose it in double quotes.
------------------------------
Date: Fri, 27 Aug 2004 15:45:27 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: exit(), die, ??
Message-Id: <cgo30o$lqj$1@misc-cct.server.rpi.edu>
Sara wrote:
> "die" IS a premature end to the script so that's normal message.
No, it's not. "Premature end of script headers" is the message a server
will output when the headers not sent correctly. It has nothing at all
to do with die(). Die simply exits the currently running script with
the current value of $!, and prints its parameters to STDERR. A test:
#!/usr/bin/env perl
use strict;
use warnings;
use CGI qw/:standard/;
print header();
print start_html('Test');
print h1('Here I am!');
die("Exiting...");
print end_html();
This program will echo the beginning HTML to the browser, as well as
'<h1>Here I am</h1>'. The program will then end, with the ending HTML
not printed. (Most browsers will render what was printed regardless of
the incorrect HTML they received). The server logs will show the
message "Exiting... at temp.cgi line 8."
> Don't worry about how you capitalize "PERL", most of us can parse your
> spelling with /i and understand what you mean. Capitalization is one
> of those cult things.
YES, AND mOST pEOPLe wiLL UNDersTAND thIS TOO, but that doesn't mean
it's okay to type like that. Perhaps Sara should read
perldoc -q difference
as well.
Paul Lalli
------------------------------
Date: 27 Aug 2004 14:05:01 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: How do you lock a file BEFORE changes are made?
Message-Id: <b893f5d4.0408271305.207754ba@posting.google.com>
Hi,
Since flock() calls have become such a hot topic recently, I've
been wondering how I can lock a file before any changes are made. Let
me provide an example:
Say I have a file with one-thousand lines of text. (If you want to
follow along, you can quickly create one with the command:
perl -le "print 'text line' foreach (1 .. 1000)" > file.txt
). Now I invoke the "interactive Perl interpreter" with the line:
perl -de 1
Now I want to open the file for writing, lock it, and then change
its contents once I acquire the lock. Normally I would do it like
this:
open(FILE, ">file.txt") or warn "Could not open: $!";
flock(FILE, LOCK_EX);
print FILE "New text lines\n" x 50;
close(FILE); # closes the file and releases the lock
This looks acceptable in that I don't modify anything until AFTER I
acquire the lock, but when I execute that first line in the
interpreter (and before I execute the next line that has the flock()
call) I can see in another window that the file's contents get cleared
out.
But that's not what I want! I don't want the file to be modified
in any way until I get the lock, but I can't get the lock until after
I open the file, and by that time the contents have already been
modified!
Is there any way to open a file for writing that won't change its
contents before I use flock()?
In case anyone is interested, here is my "perl -v" output:
This is perl, v5.8.2 built for MSWin32-x86-multi-thread
(with 25 registered patches, see perl -V for more detail)
I did find one work-around... instead of opening the file with ">",
I can open it with "+<", then use flock(), then seek to the beginning
of the file, like this:
open(FILE, "+<file.txt") or warn "Could not open: $!";
flock(FILE, LOCK_EX);
seek(FILE, 0, 0); # go to the beginning of the file
print FILE "New text lines\n" x 50;
truncate(FILE, tell(FILE)); # remove extra old data
close(FILE); # closes the file and releases the lock
Not only is this approach unfavorable because it uses extra lines of
code that seem unnecessary, but according to "perldoc -f truncate",
calling truncate() "produces a fatal error if truncate isn't
implemented on your system," which makes me think that it's not all
that portable.
Does anyone have a better way to lock a file before it's modified?
Thanks in advance.
-- Jean-Luc
------------------------------
Date: Fri, 27 Aug 2004 21:17:01 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: How do you lock a file BEFORE changes are made?
Message-Id: <Xns9552AFD178410dkwwashere@216.168.3.30>
J. Romano <jl_post@hotmail.com> wrote in message
<news:b893f5d4.0408271305.207754ba@posting.google.com>:
> But that's not what I want! I don't want the file to be
> modified in any way until I get the lock, but I can't get the
> lock until after I open the file, and by that time the contents
> have already been modified!
Maybe you want to open the file for appending or perhaps read
and write instead of just opening it for writing?
------------------------------
Date: Fri, 27 Aug 2004 23:33:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you lock a file BEFORE changes are made?
Message-Id: <2p9nlrFikb43U1@uni-berlin.de>
J. Romano wrote:
> Is there any way to open a file for writing that won't change its
> contents before I use flock()?
<snip>
> I did find one work-around... instead of opening the file with ">",
> I can open it with "+<", then use flock(), then seek to the
> beginning of the file,
I wouldn't call that a work-around; It's one of the available
solutions. It requires that the file already exists, though. If that's
not always the case, the sysopen() function offers more flexibility.
You can also open a separate lockfile and flock() that before opening
the actual file.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 27 Aug 2004 16:35:04 -0700
From: mygooglegroupsaccount@yahoo.com (Marcus)
Subject: how many days ago is 2003-07-20 ?
Message-Id: <6fc26ca7.0408271535.13659bd6@posting.google.com>
Can someone pls show the most solid way in perl to retrieve the number
of days ago a specific date string was?
Input: 2003-07-20
Output: 395
Thanks
M
------------------------------
Date: Sat, 28 Aug 2004 01:54:07 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <2p9vvbFiednmU1@uni-berlin.de>
Marcus wrote:
> Can someone pls show the most solid way in perl to retrieve the
> number of days ago a specific date string was?
>
> Input: 2003-07-20
> Output: 395
What have you tried? Personally I'd probably use Time::Local, which
would require a couple of extra lines of code, while others would use
e.g. Date::Calc.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 28 Aug 2004 00:05:13 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <slrncivin8.gig.zebee@zeus.zipworld.com.au>
In comp.lang.perl.misc on 27 Aug 2004 16:35:04 -0700
Marcus <mygooglegroupsaccount@yahoo.com> wrote:
> Can someone pls show the most solid way in perl to retrieve the number
> of days ago a specific date string was?
>
> Input: 2003-07-20
> Output: 395
>
Date::Manip is one way.
4. The amount of time between two dates.
$date1=&ParseDate($string1);
$date2=&ParseDate($string2);
$delta=&DateCalc($date1,$date2,\$err);
=> 0:0:WK:DD:HH:MM:SS the weeks, days, hours, minutes,
and seconds between the two
$delta=&DateCalc($date1,$date2,\$err,1);
=> YY:MM:WK:DD:HH:MM:SS the years, months, etc. between
the two
There are other Date modules, that's just the one I've been using
because I handle dates in all sorts of weird formats and do all sorts of
weird thigns with them, it handles everything so far.
Zebee
------------------------------
Date: 27 Aug 2004 13:57:08 -0700
From: ozgune@gmail.com (Ozgun Erdogan)
Subject: hv_iterinit has side effects - who cares about PL theory
Message-Id: <48b43181.0408271257.635a25d0@posting.google.com>
As a newbie to Perl programming, I've realized that hv_iterinit has
side effects. That is, if you want to walk over a hash structure,
there is no way you can walk over it without changing the internal
values of the hash itself. And hashes in Perl are primitive data
types.
So, if you want to read the values in a hash, there is no way for you
to do it without modifying other values in the hash itself. From my
perspective (and from my perspective only), this is some what
equivalent to:
$x = 4;
Print $x;
(now $x is 10).
I know it sounds exaggerated, and probably people discussed for a
while and thought it'd bite no one to implement it like this, but
here's where this unexpected behavior hurts:
Take CPAN module Data::Structure::Util, which detects circular
references. This is something which I really need, but goes into
infinite recursion when we have:
hash1 has a weak reference weak1 to hash2. hash2 has a hard reference
hard1 pointing back to hash1. The code goes into infinite recursion
because hv_iterinit would set xhv_riter to 0 for hash1 every time. I
think this is not a bug in Data::Structure::Util, it's a bug in Perl!
You should be able to walk over a primitive type without changing its
value, especially in a widely used language as Perl.
Are there any other Perl 5 API functions available that'd let me walk
over a hash without modifying the hash itself?
Ozgun.
------------------------------
Date: Fri, 27 Aug 2004 19:10:37 +0100
From: Stephen Kellett <snail@objmedia.demon.co.uk>
Subject: Re: Larry Wall & Cults
Message-Id: <VecqaPFdk3LBFwVF@objmedia.demon.co.uk>
In message <kw1xhujrt1.fsf@merced.netfonds.no>, Espen Vestre
<espen@*do-not-spam-me*.vestre.net> writes
>Great song, but their hard-hitting stuff is even better. For instance
>"Lisp in the Hills" or "Career of Eval".
They even provided your very own theme tune to red/black trees -
"The Red and the Black"
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk
RSI Information: http://www.objmedia.demon.co.uk/rsi.html
------------------------------
Date: Fri, 27 Aug 2004 16:31:07 -0500
From: jdoherty@nowhere.null.not (John Doherty)
Subject: Re: Larry Wall & Cults
Message-Id: <jdoherty-2708041631070001@192.168.2.178>
In article <412e199e$0$8076$a1866201@newsreader.visi.com>, Grant Edwards
<grante@visi.com> wrote:
> On 2004-08-26, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> > *** post for FREE via your newsreader at post.newsfeed.com ***
> >
> >>>>>> "Grant" == Grant Edwards <grante@visi.com> writes:
> >
> >Grant> "Guido said it, that settles it, but we're going to discuss
> >Grant> it endlessly and and vote on it using six or seven
> >Grant> different voting algorithms anyway. Then we'll argue about
> >Grant> the voting algorithms."
> >
> > Are the voting algorithms indented consistently? That's a
> > necessity, correct?
>
> Of course, but are they consistently indented using tabs or
> spaces?
AND HOW MANY SPACES PER TAB STOP?
--
------------------------------
Date: Fri, 27 Aug 2004 22:47:22 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: matching chunks of data with a regular expression
Message-Id: <cgoa5c$4gl$1@slavica.ukpost.com>
Leif Wessman wrote:
> I'm using LWP::Parallel to create several parallel requests. I would
> like to handle the result from each reqest as it come. So, I've
> registered a callback function to the user agent, like this:
>
> my $res = $ua->register($req, \&callback);
>
> In the callback function I would like to use a regular expression that
> matches 9 digits. This is what I have:
>
> sub callback {
> my($chunk,$response,$protocol) = @_;
> $chunk =~ /(\d{9})/;
> ...
> }
>
> What I wonder is what happens if I get a chunk that ends with "12345",
> and the next chunk starts with "6789". Will it get matched? If not,
> how can I change my code so it matches "123456789" even if it's in two
> different chunks?
For a general solution to this you could take a look at the working of
File::Stream.
This seems to have come up several times in the last few weeks I think
one of the people wanting this should bite the bullet and modify
File::Stream so that it can operate in a fashion where the chunks are
pushed not pulled.
------------------------------
Date: Fri, 27 Aug 2004 14:22:11 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Object Oriented programs, Perl and others
Message-Id: <livff4wiek.fsf@fmr.com>
>>>>> "DB" == Daniel Berger <djberg96@hotmail.com> writes:
DB> If you want an OO scripting language *today* consider Ruby or Python.
DB> Lord only knows when Perl6 will be out.
and you had to quote the entire post just for your 2 lines of specious
wisdom?
uri
------------------------------
Date: 27 Aug 2004 19:04:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Object Oriented programs, Perl and others
Message-Id: <cgo0kb$qq4$1@mamenchi.zrz.TU-Berlin.DE>
Matthew Braid <mb@uq.net.au.invalid> wrote in comp.lang.perl.misc:
> Hi all,
>
> I've been spending a lot of time lately writing a lot of objects for a project
> here (so far about 60 objects and counting), and while I've been considering
> security the whole way I've started thinking one level down on how to secure
> objects from direct alteration if they were used as a library in some other
> code. (At the moment this isn't _really_ an issue as the packages are not
> available to users unless they go through controlled programs that don't allow
> unknown code to run).
>
> After tinkering, I've come up with the following pseudo-rules (please
> correct me
> if I'm wrong here, and preferably give me pointers :)
>
> 1. If an object inherits from another object (in perl), it is free to
> change/override any sub inside the parent.
[lots snipped]
Your terminology is slightly off. It's classes that inherit from
one another. Saying that an object inherits something is common,
but nothing but a manner of speech. Saying that an object inherits
from another object is wrong.
On a more general note, I believe it's futile to look for general
solutions for Perl's defects it its support of OO techniques, such as
failure to enforce privacy on classes and objects. It has been noted
that Perl 6 will be fully OO and it will certainly solve these issues.
Singular solutions for one or more of these problems that are applicable
in this or that situation are still of interest. Damian's _Object
Oriented Perl_ holds quite a few of those, and more are available
among the Class::* modules. The web site http://perldesignpatterns.com
seems to be another relevant source, but I haven't seen enough of it
to have an opinion.
Anno
------------------------------
Date: Fri, 27 Aug 2004 23:17:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Own module needs loaded module from main script
Message-Id: <2p9mntFiq9vmU1@uni-berlin.de>
Bart Van der Donck wrote:
> I did some further research and come to odd results.
If you think those results are odd, you haven't spent very long time
with studying "perldoc perlmod", have you? It's good that you
experiment, but you do need to read the docs, too.
Also, you should include
use strict;
use warnings;
in the beginning of every script / module. Doing so will make Perl
help you understand what's going on.
Anyway, I have inserted a couple of comments below.
> -------------------------------------
> This is always present in main script
> -------------------------------------
> use DBI;
> use lib '/path/to/my/own/modules/';
> use DBconf; # own module
That loads the module *and* imports the %CONFIG symbol to package
main, since %CONFIG is included in the @EXPORT array.
> &DBconf::DBvars(); # returns hash with configuration values
A hash with the fully qualified name %DBconf::CONFIG is created, but
the hash is not *returned* by the subroutine.
> use MyModule; # own module
>
> ----------------------
> Case 1: MyModule has:
> ----------------------
> use DBconf;
> &DBconf::DBvars();
>
> Result of case 1: script OK.
>
> ----------------------
> Case 2: MyModule has:
> ----------------------
> &DBconf::DBvars();
>
> Result of case 2: Error: Can't call method "prepare" on an undefined
> value at /some/path/MyModule.pm line 22.
> Line 22 is the first connection string towards MySQL. DBconf::DBvars()
> should have given the connection parameters, but obviously it returned
> empty values. It probably needs "use DBconf;" first, I'ld say.
Not necessarily. But at line 22 you are apparently calling the %CONFIG
hash without using its fully qualified name, while the %CONFIG symbol
has not been imported into package MyModule.
To possible solutions, besides including "use DBconf;" in MyModule.pm:
1) Always call the %CONFIG hash with its fully qualified name, or
2) Include
BEGIN { import DBconf }
in the beginning of MyModule.pm.
> ----------------------
> Case 3: MyModule has:
> ----------------------
> use DBconf;
>
> Result of case 3: script OK
> Odd, I didn't even invoke DBconf::DBvars() !
Why would that be odd? The hash was created when the DBvars() function
was called from the main script. Why would it need to be created again?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 27 Aug 2004 18:15:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: performance surprise -- why?
Message-Id: <cgntnp$p51$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "A" == Abigail <abigail@abigail.nl> writes:
["use English" causes regex slowdown]
> A> Well, yes, but Perl is full of things that are there because of
> A> wrong decisions made in the past, and won't be changed for the sake
> A> of backwards compatability.
>
> but that was a fairly recent decision. the slowness of $& was known for
> a long time and also that english triggered it. adding the ability to
> not have english alias $& was a good idea. just no one seemed to think
> it through and select the proper default. this is a good thing to learn
> when designing apis. think carefully about which param values will be
> the most common and make them defaults.
Another option would be to conserve the documented behavior, so that
the speed penalty only occurs when $MATCH, etc. are used. One could
tie them first, so they only alias (and untie) themselves on first
usage. I don't particularly care to work out the details (a simple-
minded attempt didn't work immediately), but I'm sure it can be done.
Anno
------------------------------
Date: Fri, 27 Aug 2004 14:21:05 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: performance surprise -- why?
Message-Id: <lizn4gwige.fsf@fmr.com>
>>>>> "c" == ctcgag <ctcgag@hotmail.com> writes:
c> Joe Davison <haltingNOSPAM@comcast.net> wrote:
>>
>> So, say I do use English qw( -no_match_vars). I presume I'd still be
>> able to use the non-english versions to access the match variables,
>> should the need arise? RTFM, aye.
c> Yes and no. You could still use them, but it would have a poor effect
c> on performance. Using the match variables anywhere causes all regex to
c> slow down[1]. And apparently "use English" triggers this same penalty
c> even if you don't use explicitly use the match variables anywhere. So you
c> could use them, but would get the same performance problem.
the issue is that if the perl compiler sees $& (or its siblings)
anywhere in the code, it will enable copying on s///. note that this
should affect only s/// and not m//. the need for a copy is because $&
refers to the matched string and that may have been destroyed by the
replacement of s///. m// doesn't change anything and so $& could refer
to the original string. now, if the original string is then changed, $&
would need a copy so maybe m/// does trigger it. $& is a global so that
is why it can be anywhere in the code and trigger the copy flag. English
aliases $& to some word (who cares, i never use it) and the appearance
of $& in there triggered the copy flag. the new option causes $& to not
be seen by the compiler (if wanted, it is executed with a string
eval). as i said, this was dumb and they should have inverted the logic
of the English flag so $& is not aliased by default.
uri
------------------------------
Date: 27 Aug 2004 22:16:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: performance surprise -- why?
Message-Id: <slrncivcmi.q3p.abigail@alexandra.abigail.nl>
Uri Guttman (uri@stemsystems.com) wrote on MMMMXIV September MCMXCIII in
<URL:news:x7k6vklmhm.fsf@mail.sysarch.com>:
?? >>>>> "A" == Abigail <abigail@abigail.nl> writes:
??
?? A> Uri Guttman (uri@stemsystems.com) wrote on MMMMXIII September MCMXCIII in
?? A> <URL:news:x7sma9qx11.fsf@mail.sysarch.com>:
?? A> "" >>>>> "A" == Abigail <abigail@abigail.nl> writes:
?? A> ""
?? A> "" A> Or one could just read the manual page. From 'man English':
?? A> ""
?? A> "" A> PERFORMANCE
?? A> "" A> This module can provoke sizeable inefficiencies for
?? A> "" A> lar expressions, due to unfortunate implementation
?? A> "" A> details. If performance matters in your application
?? A> "" A> you don't need $PREMATCH, $MATCH, or $POSTMATCH, try
?? A> ""
?? A> "" A> use English qw( -no_match_vars ) ;
?? A> ""
?? A> "" and as damian conway says (and i agree) they chose the wrong default
?? A> "" that option. it should have been -use_match_vars and the default for
?? A> "" english should be to not alias them.
??
?? A> Well, yes, but Perl is full of things that are there because of
?? A> wrong decisions made in the past, and won't be changed for the sake
?? A> of backwards compatability.
??
?? but that was a fairly recent decision. the slowness of $& was known for
?? a long time and also that english triggered it. adding the ability to
?? not have english alias $& was a good idea. just no one seemed to think
?? it through and select the proper default. this is a good thing to learn
?? when designing apis. think carefully about which param values will be
?? the most common and make them defaults.
If I remember correctly, the decision to alias them by default was taken
on purpose. By not including $MATCH and friends on a 'use English;' any
program that used 'use English;' and '$MATCH' would break on an upgrade
of Perl. P5p is very reluctant to break anything - and IMO rightly so.
Personally, I think the existance of 'English.pm' is the thing to regret,
not the fact that it includes a link to $& by default.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: 27 Aug 2004 22:23:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: performance surprise -- why?
Message-Id: <slrncivd2u.q3p.abigail@alexandra.abigail.nl>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMXIV September
MCMXCIII in <URL:news:cgntnp$p51$1@mamenchi.zrz.TU-Berlin.DE>:
;; Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
;; > >>>>> "A" == Abigail <abigail@abigail.nl> writes:
;;
;; ["use English" causes regex slowdown]
;;
;; > A> Well, yes, but Perl is full of things that are there because of
;; > A> wrong decisions made in the past, and won't be changed for the sake
;; > A> of backwards compatability.
;; >
;; > but that was a fairly recent decision. the slowness of $& was known for
;; > a long time and also that english triggered it. adding the ability to
;; > not have english alias $& was a good idea. just no one seemed to think
;; > it through and select the proper default. this is a good thing to learn
;; > when designing apis. think carefully about which param values will be
;; > the most common and make them defaults.
;;
;; Another option would be to conserve the documented behavior, so that
;; the speed penalty only occurs when $MATCH, etc. are used. One could
;; tie them first, so they only alias (and untie) themselves on first
;; usage. I don't particularly care to work out the details (a simple-
;; minded attempt didn't work immediately), but I'm sure it can be done.
That wouldn't work. $& etc can only work if work is done when the
match occurs - if you delay it till $& is actually used, the necessary
information is gone. That's why the penalty occurs if the *compiler*
detect $&, not the runtime.
Witness:
#!/usr/bin/perl
use strict;
use warnings;
no warnings qw /syntax/;
"foo" =~ /o/;
eval 'print "$&\n"'; # Compiler sees this after the match.
exit;
__END__
Use of uninitialized value in concatenation (.) or string at (eval 1) line 1
But now we add a $& that's only seen at compile time:
#!/usr/bin/perl
use strict;
use warnings;
no warnings qw /syntax/;
"foo" =~ /o/;
eval 'print "$&\n"'; # Compiler sees this after the match.
exit;
my $foo = $&;
__END__
o
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
------------------------------
Date: 27 Aug 2004 18:35:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: subroutines with XML
Message-Id: <cgnusv$pp9$1@mamenchi.zrz.TU-Berlin.DE>
Sara <sa_ravenone@yahoo.com> wrote in comp.lang.perl.misc:
> Hi all,
> Thanks to the guidance provided for an earlier query I am progressing
> into references and objects.
>
> Now I want to associate every element of an XML file with a
> subroutine. I searched CPAN and also read Perl-XML FAQ; XML::Dumper is
> excellent and almost exactly what I wanted but it doesn't support
> references to Perl subroutines. I'm new to using Perl with XML, though
> I have used Perl and XML separately for quite some time. Is there any
> easy way to associate XML elements with specific subroutines. I
> thought of using symbolic references in haste then didn't do so
> because I was reminded of the advice given by many in this community.
The advice usually goes on "...use a hash instead".
> Is it necessary to have elements of XML declared as part of a data
> structure in the program to make this association work?
In one way or another, yes. You need some string that uniquely identifies
each XML element (whatever that is). If they are themselves strings, fine.
If they are objects, they will stringify to a unique string. If they are
compounds, use a reference, which will also be unique. Build a hash (a
dispatch-table) like this:
my %table = (
$el1 => sub {
# code here
},
$el2 => \ &named_sub,
# more entries
);
That shows two ways of entering a coderef in a hash, compiled in
place, or using a named sub compiled elsewhere.
Later, given an XML element $element, you can call the code like this:
my $result = $table{ $element}->( $arg1, ...);
Anno
------------------------------
Date: Fri, 27 Aug 2004 18:39:12 +0000
From: Brendon Caligari <bcaligari@nospam.fireforged.com>
Subject: Re: Xah Lee's Unixism
Message-Id: <412f7fd0$0$6328$bed64819@news.gradwell.net>
>
> $ telnet xahlee.org 80;
> Trying 208.186.130.4...
> Connected to xahlee.org.
> Escape character is '^]'.
> GET / HTTP/1.1
>
> HTTP/1.1 400 Bad Request
> Date: Fri, 27 Aug 2004 01:35:52 GMT
> Server: Apache/2.0.50 (Fedora)
> ^^^^^^^^^^^^^^^^^^^^^^
It's a hosting provider. Funny though how they would use something like
Fedora.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6923
***************************************