You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Paul <yd...@yahoo.com> on 2001/03/14 22:08:56 UTC
Very[OT]:Technical query re: scratchpad lookups for my() vars
Anybody know offhand *why* my() lexicals are supposedly faster?
If they're stored on a scratchpad for the scope, which is an array,
(technically a stack of them to accommodate recursion,) then exactly
how does Perl go about finding which data location you mean when you
say $x for a lexical? $::x has to go through the package lookup, which
(if I recall correctly) is technically a hash element of a hash element
at least......but if the scratchpad has a lot of scope-specific
lexicals, how does it find which one is x?
my $brain = 'tapioca'; #=o)
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Posted by "Alexander Farber (EED)" <ee...@eed.ericsson.se>.
Paul wrote:
> None of this is critical for anything I'm doing right now, but I'm a
> detail hound. I want to *understand* it, so that in the future I can
> make intelligent decisions about what would be a "better" way to write
> any given algorithm, without just relying on popular wisdom and "urban
> legend". =o)
If you're a "detail hound", why don't you look into the perl source code?
Re: VeryOT: help needed
Posted by Matt Sergeant <ma...@sergeant.org>.
On Thu, 15 Mar 2001, Jauder Ho wrote:
> Alright, it's crunch time (trying to help a coworker out) and I need
> to pick up some XML parsing with perl fast. So if anyone here has some
> good resources, they can point me at, it would be much appreciated.
>
> The problem I am trying to solve is as follows: I have two XML files, one
> is encoded in UTF8 and the other is in ASCII7. I need to parse the ASCII7
> file first and if a tag exists in the UTF8 file replace the data in the
> ASCII7 file with the UTF8 info. Everything should then be output in a UTF8
> format.
>
> Pointers to manipulating XML needed but I would take any additional help.
> Thanks.
There is actually a list for perl and xml, for what it's worth, where this
would be on topic... Anyway, I'm going to be totally unbiased here and
suggest you look at XML::XPath. I'm not 100% certain what you're trying to
achieve, but most things are pretty simple with XPath. Contact me offline
if you have further questions.
--
<Matt/>
/|| ** Founder and CTO ** ** http://axkit.com/ **
//|| ** AxKit.com Ltd ** ** XML Application Serving **
// || ** http://axkit.org ** ** XSLT, XPathScript, XSP **
// \\| // ** mod_perl news and resources: http://take23.org **
\\//
//\\
// \\
VeryOT: help needed
Posted by Jauder Ho <ja...@carumba.com>.
Alright, it's crunch time (trying to help a coworker out) and I need to
pick up some XML parsing with perl fast. So if anyone here has some good
resources, they can point me at, it would be much appreciated.
The problem I am trying to solve is as follows: I have two XML files, one
is encoded in UTF8 and the other is in ASCII7. I need to parse the ASCII7
file first and if a tag exists in the UTF8 file replace the data in the
ASCII7 file with the UTF8 info. Everything should then be output in a UTF8
format.
Pointers to manipulating XML needed but I would take any additional help.
Thanks.
--Jauder
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Posted by Paul <yd...@yahoo.com>.
--- Elizabeth Mattijsen <li...@dijkmat.nl> wrote:
> At 03:52 PM 3/14/01 -0800, Paul wrote:
> But nothing about the structural/algorithmic mechanics. :<
>
> From the perlsub docs:
>
> Variables declared with my are not part of any package and are
> therefore
> never fully qualified with the package name. In particular, you're
> not
> allowed to try to make a package variable (or other global) lexical:
>
> my $pack::var; # ERROR! Illegal syntax
> my $_; # also illegal (currently)
> In fact, a dynamic variable (also known as package or global
> variables) are
> still accessible using the fully qualified :: notation even while a
> lexical
> of the same name is also visible:
>
> package main;
> local $x = 10;
> my $x = 20;
> print "$x and $::x\n";
> That will print out 20 and 10.
>
> There is _no_ stash of lexicals during execution, only during
> compilation. I guess one of the reasons lexicals are faster.
>
>
> Elizabeth Mattijsen
An excellent example, all known and understood.
What I can't find is this:
I know that my($x) puts x on this scope's scratchpad (and not in any
package space), but rather than a hash named main:: with a key named x
(which is, as I understand it, an oversimplification perhaps, but
basically what Perl does internally for $main::x), exactly *how* does
Perl "put" x into the scratchpad AV*? and once it's there, what did it
store? How does it know that entry is 'x'? is it just a reference to
the actual value?
None of this is critical for anything I'm doing right now, but I'm a
detail hound. I want to *understand* it, so that in the future I can
make intelligent decisions about what would be a "better" way to write
any given algorithm, without just relying on popular wisdom and "urban
legend". =o)
(That's why I said it was Very[OT], lol....)
Paul
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
Re: Very[OT]:Technical query re: scratchpad lookups for my()
vars
Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 03:52 PM 3/14/01 -0800, Paul wrote:
But nothing about the structural/algorithmic mechanics. :<
From the perlsub docs:
Variables declared with my are not part of any package and are therefore
never fully qualified with the package name. In particular, you're not
allowed to try to make a package variable (or other global) lexical:
my $pack::var; # ERROR! Illegal syntax
my $_; # also illegal (currently)
In fact, a dynamic variable (also known as package or global variables) are
still accessible using the fully qualified :: notation even while a lexical
of the same name is also visible:
package main;
local $x = 10;
my $x = 20;
print "$x and $::x\n";
That will print out 20 and 10.
There is _no_ stash of lexicals during execution, only during
compilation. I guess one of the reasons lexicals are faster.
Elizabeth Mattijsen
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Posted by "Alexander Farber (EED)" <ee...@eed.ericsson.se>.
Paul wrote:
> --- Robert Landrum <rl...@capitoladvantage.com> wrote:
> > I could be wrong, but as I recall, when your program enters a scope,
> > perl immediatly identifies the the scratchpad to use. Then, it need
> > only search backwards up the tree of scratchpads to find the variable
> > "$x", which is faster than iterating through the STHASH looking for a
> > localized or global $x.
>
> But how does it locate x in the scratchpad? Where're the docs?
> Or am I gonna have to read the code? =lol!
Chapter 20 in "Advanced Perl programming"
[OT] do { local *FH; }
Posted by Matt Sergeant <ma...@sergeant.org>.
On Wed, 14 Mar 2001, Paul wrote:
> Learned a new trick:
> my $fh = do { local *FH; };
I've had trouble using this under mod_perl - bizarre results with it not
actually being lexical and not closing the file. I had to resort to using
Apache->gensym in the end. Has anyone else seen the same?
--
<Matt/>
/|| ** Founder and CTO ** ** http://axkit.com/ **
//|| ** AxKit.com Ltd ** ** XML Application Serving **
// || ** http://axkit.org ** ** XSLT, XPathScript, XSP **
// \\| // ** mod_perl news and resources: http://take23.org **
\\//
//\\
// \\
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Posted by Paul <yd...@yahoo.com>.
--- Robert Landrum <rl...@capitoladvantage.com> wrote:
> I could be wrong, but as I recall, when your program enters a scope,
> perl immediatly identifies the the scratchpad to use. Then, it need
> only search backwards up the tree of scratchpads to find the variable
> "$x", which is faster than iterating through the STHASH looking for a
> localized or global $x.
But how does it locate x in the scratchpad? Where're the docs?
Or am I gonna have to read the code? =lol!
> I think Mark-Jason Dominus has much more indepth look at the perl
> internals on his website... plover.com
Great articles, read them today.
Learned a new trick:
my $fh = do { local *FH; };
But nothing about the structural/algorithmic mechanics. :<
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Posted by Robert Landrum <rl...@capitoladvantage.com>.
I could be wrong, but as I recall, when your program enters a scope,
perl immediatly identifies the the scratchpad to use. Then, it need
only search backwards up the tree of scratchpads to find the variable
"$x", which is faster than iterating through the STHASH looking for a
localized or global $x.
I think Mark-Jason Dominus has much more indepth look at the perl
internals on his website... plover.com
Robert Landrum
>Anybody know offhand *why* my() lexicals are supposedly faster?
>If they're stored on a scratchpad for the scope, which is an array,
>(technically a stack of them to accommodate recursion,) then exactly
>how does Perl go about finding which data location you mean when you
>say $x for a lexical? $::x has to go through the package lookup, which
>(if I recall correctly) is technically a hash element of a hash element
>at least......but if the scratchpad has a lot of scope-specific
>lexicals, how does it find which one is x?
>
>my $brain = 'tapioca'; #=o)
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Auctions - Buy the things you want at great prices.
>http://auctions.yahoo.com/
--
Warning: The contents of this message are made of bits which may or may not
be an accurate representation of my thoughts.