On 07/09/2011 20:49, Emeka wrote:
On Wed, Sep 7, 2011 at 8:00 PM, Rob Dixon<rob.di...@gmx.com> wrote:
On Wed, Sep 7, 2011 at 8:08 PM, Emeka<emekami...@gmail.com> wrote:
On 06/09/2011 13:04, Emeka wrote:
Could someone explain what Perl does behind here?
Assign to Substring..
substr($string, 0 , 5) = 'Greetings';
What do you want to know Emeka?
There is no copy of the 'old' string, and substr behaves as documented.
I have the C code of substr in front of me, but there is little else to
say.
I want to check out the C code. Kindly mail it to my box.
Have a great day!
Which C file should check out?
Hi Emeka.
It would help a lot if you would start putting your responses at the end
of the post you are replying to. That way extended threads are made much
more readable.
As Shlomi said, the code for the substr op is "PP(pp_substr)" pp.c. Most
of the code there is for validating the parameters and deciding which of
several different things should be done. It doesn't actually do any
substring extraction, it just sets up the return value TARG and pushes
it onto the stack.
The code that deals specifically with lvalues is the block starting
else if (lvalue) { /* it's an lvalue! */
at line 3253 in the version I'm looking at, 5.12.4. In particular you
will see that it assigns
LvTARGOFF(TARG) = pos;
LvTARGLEN(TARG) = len;
to indicate the position and length of the substring that TARG specifies.
The assignment to the substring is done by function
'Perl_magic_setsubstr' in mg.c. Which ultimately calls 'sv_insert',
#defined in sv.h as a call to Perl_sv_insert_flags' which is in sv.c.
I hope that helps. The internals of Perl are complex and not for the
feint-hearted.
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/