[25135] in Perl-Users-Digest
Perl-Users Digest, Issue: 7384 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 9 11:10:39 2004
Date: Tue, 9 Nov 2004 08:10:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 9 Nov 2004 Volume: 10 Number: 7384
Today's topics:
Re: Reflection or discovery of object methods in perl? (Anno Siegel)
Re: Reflection or discovery of object methods in perl? ()
Re: Reflection or discovery of object methods in perl? (Anno Siegel)
Re: Reflection or discovery of object methods in perl? ()
Re: Reflection or discovery of object methods in perl? <uri@stemsystems.com>
Re: Reflection or discovery of object methods in perl? <uri@stemsystems.com>
Re: Reflection or discovery of object methods in perl? ()
Re: Reflection or discovery of object methods in perl? (Peter Scott)
Re: Reflection or discovery of object methods in perl? (Anno Siegel)
why is pattern matching using '|' slower than 2 separat <Mark.Seger@hp.com>
Re: why is pattern matching using '|' slower than 2 sep <daveandniki@ntlworld.com>
Re: why is pattern matching using '|' slower than 2 sep <jwillmore@fastmail.us>
Re: why is pattern matching using '|' slower than 2 sep <1usa@llenroc.ude.invalid>
Re: why is pattern matching using '|' slower than 2 sep <uri@stemsystems.com>
Re: why is pattern matching using '|' slower than 2 sep <uri@stemsystems.com>
Re: why not print $A[0] <mritty@gmail.com>
Re: why not print $A[0] <usenet@morrow.me.uk>
Win32::IE::Mechanize multiple frame problem (sebastian)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Nov 2004 11:28:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmq9lh$3u2$1@mamenchi.zrz.TU-Berlin.DE>
<bboett@adlp.org> wrote in comp.lang.perl.misc:
> hello!
>
> again i am trying to get some stuff working (this time CORBA...), and again
> i would need an inspection tool telling me what class an object is
> and what methods its possesses...
The class is easy: perldoc -f ref. Finding all methods can't be done.
One could (conceivably) walk the symbol table of the class and extract
all coderefs (plus, recursively, the classes on @ISA). But there is
no way of telling if a sub is a public method (or a method at all),
so you'd get a lot of garbage besides the actual methods, and no
way to tell one from the other.
Anno
------------------------------
Date: 9 Nov 2004 12:15:56 GMT
From: bboett@sept.u-strasbg.fr ()
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmqcds$g2p$1@news.u-strasbg.fr>
In article <cmq9lh$3u2$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>The class is easy: perldoc -f ref. Finding all methods can't be done.
hmmm pity....
>One could (conceivably) walk the symbol table of the class and extract
>all coderefs (plus, recursively, the classes on @ISA). But there is
>no way of telling if a sub is a public method (or a method at all),
>so you'd get a lot of garbage besides the actual methods, and no
>way to tell one from the other.
ok! where do i find those symbol tables?
--
bboett at inforezo dot u-strasbg dot fr
http://inforezo.u-strasbg.fr/~bboett
==============================================================
Unsolicited commercial email is NOT welcome at this email address
------------------------------
Date: 9 Nov 2004 12:25:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmqd0j$67n$1@mamenchi.zrz.TU-Berlin.DE>
<bboett@adlp.org> wrote in comp.lang.perl.misc:
> In article <cmq9lh$3u2$1@mamenchi.zrz.TU-Berlin.DE>,
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> >The class is easy: perldoc -f ref. Finding all methods can't be done.
> hmmm pity....
>
> >One could (conceivably) walk the symbol table of the class and extract
> >all coderefs (plus, recursively, the classes on @ISA). But there is
> >no way of telling if a sub is a public method (or a method at all),
> >so you'd get a lot of garbage besides the actual methods, and no
> >way to tell one from the other.
> ok! where do i find those symbol tables?
In perldata, perlmod and perlsub, mainly.
Here is an example that lists all subs in main (scratch the "grep"
to see all symbols):
sub foo {} # define a sub, or you won't see much
print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::
You'll have to use some nasty symrefs to make it use an arbitrary
string instead of "main". That is one of the cases where symrefs
are officially tolerated.
Anno
------------------------------
Date: 9 Nov 2004 13:01:06 GMT
From: bboett@sept.u-strasbg.fr ()
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmqf2i$gl1$1@news.u-strasbg.fr>
In article <cmqd0j$67n$1@mamenchi.zrz.TU-Berlin.DE>,
>Here is an example that lists all subs in main (scratch the "grep"
>to see all symbols):
>
> sub foo {} # define a sub, or you won't see much
> print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::
interesting :D i was planning to use the 'can' method to achieve the same :D
anyway thanks a lot!
making myself an inspection class
ciao
Bruno
--
ciao
Bruno
Bruno.Boettcher at visualsphere dot com
------------------------------
Date: Tue, 09 Nov 2004 14:43:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <x7zn1r84n7.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> Here is an example that lists all subs in main (scratch the "grep"
AS> to see all symbols):
AS> sub foo {} # define a sub, or you won't see much
AS> print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::
AS> You'll have to use some nasty symrefs to make it use an arbitrary
AS> string instead of "main". That is one of the cases where symrefs
AS> are officially tolerated.
as my rule states, use symrefs only when you are munging (which covers
searching :) the symbol table. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 09 Nov 2004 14:45:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <x7wtwv84ih.fsf@mail.sysarch.com>
>>>>> "B" == <bboett@sept.u-strasbg.fr> writes:
B> In article <cmqd0j$67n$1@mamenchi.zrz.TU-Berlin.DE>,
>> Here is an example that lists all subs in main (scratch the "grep"
>> to see all symbols):
>>
>> sub foo {} # define a sub, or you won't see much
>> print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::
B> interesting :D i was planning to use the 'can' method to achieve
B> the same :D anyway thanks a lot!
how would you use can() for introspection? you would have to search all
possible strings and run can() on them.
also with AUTOLOAD you can't fully tell what methods are there. autoload
can handle any method, or decide what is available at run time or
whatever. i find the concept of introspection to be weak and not needed
much. but others seems to live on it. either you know the classes you
want or you don't.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 9 Nov 2004 15:06:50 GMT
From: bboett@sept.u-strasbg.fr ()
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmqmea$i14$1@news.u-strasbg.fr>
In article <x7wtwv84ih.fsf@mail.sysarch.com>,
Uri Guttman <uri@stemsystems.com> wrote:
>how would you use can() for introspection? you would have to search all
>possible strings and run can() on them.
yep that's what i do, spares one eval statement...
that way i can separate also what are variables...
BTW a chance to easily try to extrapolate what return type the subs
might have (means without actually executing them...)?
>also with AUTOLOAD you can't fully tell what methods are there. autoload
>can handle any method, or decide what is available at run time or
sure...
but not in my code :D
>whatever. i find the concept of introspection to be weak and not needed
>much. but others seems to live on it. either you know the classes you
>want or you don't.
well in most cases yes, when you are debugging a non working CORBA
framework (at least non working for me...) with perl objects that have no
(or nearly no) documentation, it can come in quite handy...
ciao
Bruno
Bruno.Boettcher at visualsphere dot com
==============================================================
Unsolicited commercial email is NOT welcome at this email address
--
ciao
Bruno
Bruno.Boettcher at visualsphere dot com
------------------------------
Date: Tue, 09 Nov 2004 15:25:17 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <xj5kd.163947$nl.143728@pd7tw3no>
In article <cmq8q7$fcq$1@news.u-strasbg.fr>,
bboett@sept.u-strasbg.fr () writes:
>again i am trying to get some stuff working (this time CORBA...), and again
>i would need an inspection tool telling me what class an object is
>and what methods its possesses...
>
>i know UNIVERSAL::can but that one expects a method name, it doesn't spit
>out the whole list when not provided with a method name...
>
>so is there that type of mechanism in perl?
http://search.cpan.org/dist/Class-Inspector/lib/Class/Inspector.pm#methods_$class,_@options
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
------------------------------
Date: 9 Nov 2004 16:02:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmqpmu$uf$1@mamenchi.zrz.TU-Berlin.DE>
<bboett@adlp.org> wrote in comp.lang.perl.misc:
> In article <x7wtwv84ih.fsf@mail.sysarch.com>,
> BTW a chance to easily try to extrapolate what return type the subs
> might have (means without actually executing them...)?
No.
That doesn't even make sense in a Perl context. For one, Perl doesn't have
the concept of data type in the sense C has it. The scalar/array/hash/...
distinction comes closest, in particular in combination with references.
But a function can return any of these at run time, there's no way of
telling unless you analyze the code.
Anno
------------------------------
Date: Tue, 09 Nov 2004 08:53:12 -0500
From: Mark Seger <Mark.Seger@hp.com>
Subject: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <4190cdae$1@usenet01.boi.hp.com>
I constructed a very simply step to compare two ways to do pattern
matching and found using the '|' to check for two patterns to be a lot
slower than 2 separate tests of one pattern each. Most surprising!
Consider the following:
#!/usr/bin/perl
$z='ZZZZZZZZZZZZZZZZZZZZZ';
for ($i=0; $i<1000000; $i++)
{
$a=1 if $z=~/xxxxx|yyyyy/;
# $a=1 if $z=~/xxxxx/ or $z=~/yyyyy/;
}
[root@dl380-1 collectl]# time ./test.pl
real 0m4.526s
user 0m4.320s
sys 0m0.000s
if I comment out the first test and uncomment the second one I get
[root@dl380-1 collectl]# time ./test.pl
real 0m0.702s
user 0m0.690s
sys 0m0.010s
As one might expect, when the strings get bigger or the number of tests
increase, the difference in test runs get even bigger. Comments?
-mark
------------------------------
Date: Tue, 09 Nov 2004 14:25:03 GMT
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <3r4kd.189$Av5.115@newsfe4-gui.ntli.net>
"Mark Seger" <Mark.Seger@hp.com> wrote in message
news:4190cdae$1@usenet01.boi.hp.com...
>I constructed a very simply step to compare two ways to do pattern matching
>and found using the '|' to check for two patterns to be a lot slower than 2
>separate tests of one pattern each. Most surprising!
>
> Consider the following:
>
> #!/usr/bin/perl
> $z='ZZZZZZZZZZZZZZZZZZZZZ';
> for ($i=0; $i<1000000; $i++)
> {
> $a=1 if $z=~/xxxxx|yyyyy/;
> # $a=1 if $z=~/xxxxx/ or $z=~/yyyyy/;
> }
>
> [root@dl380-1 collectl]# time ./test.pl
> real 0m4.526s
> user 0m4.320s
> sys 0m0.000s
>
> if I comment out the first test and uncomment the second one I get
>
> [root@dl380-1 collectl]# time ./test.pl
> real 0m0.702s
> user 0m0.690s
> sys 0m0.010s
>
> As one might expect, when the strings get bigger or the number of tests
> increase, the difference in test runs get even bigger. Comments?
>
> -mark
For the answer to this and more (if you are interested) have a look at
Mastering Regular Expressions by Jeremy Friedl
The short answer is that the behaviour is entirely expected. The first
version caused the Regex engine to do lots of switching at each position in
the string to swap between looking for one then the other. It also hinders
the engine from doing certain optimisations which are easy with the simple
literal string.
Dave
------------------------------
Date: Tue, 09 Nov 2004 10:54:00 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <pan.2004.11.09.15.53.59.12888@fastmail.us>
On Tue, 09 Nov 2004 08:53:12 -0500, Mark Seger wrote:
<snip>
> Consider the following:
>
> #!/usr/bin/perl
> $z='ZZZZZZZZZZZZZZZZZZZZZ';
> for ($i=0; $i<1000000; $i++)
> {
> $a=1 if $z=~/xxxxx|yyyyy/;
> # $a=1 if $z=~/xxxxx/ or $z=~/yyyyy/;
> }
>
> [root@dl380-1 collectl]# time ./test.pl
> real 0m4.526s
> user 0m4.320s
> sys 0m0.000s
>
> if I comment out the first test and uncomment the second one I get
>
> [root@dl380-1 collectl]# time ./test.pl
> real 0m0.702s
> user 0m0.690s
> sys 0m0.010s
>
> As one might expect, when the strings get bigger or the number of tests
> increase, the difference in test runs get even bigger. Comments?
You might want to throw in the 'o' modifier to the regexs if the only
thing you're doing is matching. This might yield different results.
For example:
#!/usr/bin/perl
$z='ZZZZZZZZZZZZZZZZZZZZZ';
for ($i=0; $i<1000000; $i++)
{
$a=1 if $z=~/xxxxx|yyyyy/o;
# $a=1 if $z=~/xxxxx/o or $z=~/yyyyy/o;
}
The 'o' modifier compiles the regex once, so it doesn't need to be
compiled latter on. Running the same tests on my system showed some
improvement, but not much.
Check out perlretut for more information.
HTH
Jim
------------------------------
Date: 9 Nov 2004 15:56:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <Xns959C6F4B81A2Fasu1cornelledu@132.236.56.8>
James Willmore <jwillmore@fastmail.us> wrote in
news:pan.2004.11.09.15.53.59.12888@fastmail.us:
> On Tue, 09 Nov 2004 08:53:12 -0500, Mark Seger wrote:
>
> <snip>
>> Consider the following:
>>
>> #!/usr/bin/perl
>> $z='ZZZZZZZZZZZZZZZZZZZZZ';
>> for ($i=0; $i<1000000; $i++)
>> {
>> $a=1 if $z=~/xxxxx|yyyyy/;
>> # $a=1 if $z=~/xxxxx/ or $z=~/yyyyy/;
...
> You might want to throw in the 'o' modifier to the regexs
Why? There is no interpolation happening here.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Tue, 09 Nov 2004 15:58:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <x7d5yn815l.fsf@mail.sysarch.com>
>>>>> "JW" == James Willmore <jwillmore@fastmail.us> writes:
JW> $a=1 if $z=~/xxxxx|yyyyy/o;
JW> # $a=1 if $z=~/xxxxx/o or $z=~/yyyyy/o;
JW> The 'o' modifier compiles the regex once, so it doesn't need to be
JW> compiled latter on. Running the same tests on my system showed some
JW> improvement, but not much.
/o only doesn't recompile when there are variables in the regex. a fixed
string regex like those won't get any help from /o. and in recent perls
the regex is not recompiled if the variables haven't changed so much of
the need for /o is gone. also with qr// to handle compiling a regex once
and allowing its reuse, the need for /o is almost totally gone.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 09 Nov 2004 15:58:50 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <x7ekj38164.fsf@mail.sysarch.com>
>>>>> "JW" == James Willmore <jwillmore@fastmail.us> writes:
JW> $a=1 if $z=~/xxxxx|yyyyy/o;
JW> # $a=1 if $z=~/xxxxx/o or $z=~/yyyyy/o;
JW> The 'o' modifier compiles the regex once, so it doesn't need to be
JW> compiled latter on. Running the same tests on my system showed some
JW> improvement, but not much.
/o only doesn't recompile when there are variables in the regex. a fixed
string regex like those won't get any help from /o. and in recent perls
the regex is not recompiled if the variables haven't changed so much of
the need for /o is gone. also with qr// to handle compiling a regex once
and allowing its reuse, the need for /o is almost totally gone.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 09 Nov 2004 13:35:43 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: why not print $A[0]
Message-Id: <PI3kd.1036$4U1.99@trndny05>
"Mark Galecki" <mark_galeck_spam_magnet@yahoo.com> wrote in message
news:50064a21.0411081941.5734c477@posting.google.com...
> I downloaded Perl from Cygwin (I know I
> know, Windows, well, that's what my employer uses), and they don't
> even have "perldoc".
Nonsense. perldoc is a standard tool that comes with Perl, including
the Cygwin version of Perl. I don't recall offhand if it's listed as a
seperate package in Cygwin's setup.exe utility, but it's definately on
my installation.
What happens when you type (for example)
perldoc perl
in your cygwin shell?
Paul Lalli
------------------------------
Date: Tue, 9 Nov 2004 00:40:19 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: why not print $A[0]
Message-Id: <j8g562-7p7.ln1@osiris.mauzo.dyndns.org>
Quoth mark_galeck_spam_magnet@yahoo.com (Mark Galecki):
> OK, I am sorry about the apparent lack of context. I purposely
> omitted some details which I thought were irrelevant, to not waste
> your time. I guess I overdid it.
>
> So what I can understand from the responses, is that I have to do
>
> print {$A[0]} "foo\n";
>
> or
> $a = $A[0]; print $a "foo\n";
>
> but not
> print $A[0] "foo\n";
>
> because of the way the Perl parser works. OK I can accept that.
>
> But please, can someone point me to where this is written down in the
> Camel book? (I really tried to find it there ). Or is it?
Where expected, under print on p766; the general discussion of 'indirect
object syntax' is in the objects section on p314 (3rd ed.).
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: 9 Nov 2004 06:13:50 -0800
From: sebastian_tay@geocities.com (sebastian)
Subject: Win32::IE::Mechanize multiple frame problem
Message-Id: <5e952f3e.0411090613.39e2232d@posting.google.com>
Hi all,
I am using Win32::IE::Mechanize. I encounter a website that has
multiple frames and the frames are interdepdent with one another. And,
the actions required to be performed at different frames. I need to
set some frame 'in-focus' at different times so that i can access the
right objects in different frames.
Are there any APIs in Mechanize to do that? follow_link, load_frame
will actually loads the URL into the whole IE and end up it complains
that it can't find some parent frames.
Are there any other ways to go around that?
Thanks in advanced.
Cheers
Sebastian
------------------------------
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 7384
***************************************