FAQ

On Tue May 31 05:29:03 2016, oainikusama@gmail.com wrote:
Hi everyone,

I have spoken to Zefram and TonyC on #p5p, and apparently it's not well
documented in perl which operations will eagerly create hash elements. In
foo(\$x{bla}), for example, the \ is treating its operand as an lvalue,
same as if it were on the lhs of an assignment like that. Now, foo($x{bla})
*also* treats $x{bla} as an lvalue, but doesn't eagerly create it. Instead,
it passes a PVLV to foo(), which can then create the hash element by
assigning to $_[0].

Function arguments are usually taken by value but there's no type
information to say which arguments specifically are taken by reference and
so need the lvalue treatment. This patch adds two extra tests for that
behaviour, so at least we can check whether they remain consistent.

Hope it helps :)
Thanks!

garu
Here's the commit message:

#####
It's not well documented which operations will eagerly create hash
elements. In foo(\$x{bla}), for example, the \ is treating its
operand as an lvalue, same as if it were on the lhs of an assignment
like that. Now, foo($x{bla}) *also* treats $x{bla} as an lvalue, but
doesn't eagerly create it. Instead, it passes a PVLV to foo(), which
can then create the hash element by assigning to $_[0].

Function arguments are usually taken by value but there's no type
information to say which arguments specifically are taken by
reference and so need the lvalue treatment. This patch adds two
extra tests for that behaviour, so at least they remain consistent.
#####

... and here are the added tests:

#####
+# Test to see if hash values are eagerly created
+{
+ sub myspringersub {}
+ myspringersub($spring3{"foo"});
+ is (scalar keys %spring3, 0, 'regular key was not eagerly created after sub call');
+ myspringersub(\$spring3{"foo"});
+ ok (exists $spring3{"foo"}, 'referenced key was eagerly created after sub call');
+}
+
#####

Now, there's a lot of analysis packed into that commit message -- but I'm not sure that all of it is reflected in the tests.

The commit message has two paragraphs. The first focuses on lvalues; the second on function arguments. The tests seem to me to focus only on the second.

I don't think there is anything really *wrong* here -- but I wonder if the combination of the commit message and the tests really clarifies the issue for people (like me) who are not experts in the perlguts.

Thank you very much.

--
James E Keenan (jkeenan@cpan.org)

---
via perlbug: queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=128301

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupperl5-porters @
categoriesperl
postedMay 31, '16 at 10:40p
activeJun 1, '16 at 12:28a
posts3
users2
websiteperl.org

2 users in discussion

Zefram: 2 posts James E Keenan via RT: 1 post

People

Translate

site design / logo © 2017 Grokbase