summaryrefslogtreecommitdiff
path: root/pod/perltrap.pod
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@engin.umich.edu>1997-02-24 17:29:30 -0500
committerChip Salzenberg <chip@atlantic.net>1997-02-22 02:41:53 +1200
commitdfdcb7a067c15e57f49dda89180ef92cb98eb798 (patch)
tree07849571a37648c2bbb92102205cebd101167593 /pod/perltrap.pod
parent55479bb671272502420f9e5f7617b1b0be8544af (diff)
downloadperl-dfdcb7a067c15e57f49dda89180ef92cb98eb798.tar.gz
Re: Hash key created by subroutine call? (fwd)
On Mon, 24 Feb 1997 06:20:14 MST, Tom Christiansen wrote: >Considering how frequently this gets asked, how about >putting it in perlsub? > >------- start of forwarded message ------- >From: Rick Smith <ricks@sd.znet.com> >Newsgroups: comp.lang.perl.misc >Subject: Hash key created by subroutine call? >Date: Sat, 22 Feb 1997 21:47:52 -0800 I seem to be in a documental state today. p5p-msgid: <199702242229.RAA04395@aatma.engin.umich.edu>
Diffstat (limited to 'pod/perltrap.pod')
-rw-r--r--pod/perltrap.pod20
1 files changed, 20 insertions, 0 deletions
diff --git a/pod/perltrap.pod b/pod/perltrap.pod
index 05cb02b47b..a179b8b5a8 100644
--- a/pod/perltrap.pod
+++ b/pod/perltrap.pod
@@ -1137,6 +1137,26 @@ general subroutine traps. Includes some OS-Specific traps.
=over 5
+=item * Subroutine calls provide lvalue context to arguments
+
+Beginning with version 5.002, all subroutine arguments are consistently
+given a "value may be modified" context, since all subroutines are able
+to modify their arguments by explicitly referring to C<$_[0]> etc.
+This means that any array and hash elements provided as arguments
+will B<always be created> if they did not exist at the time
+the subroutine is called. (perl5 versions before 5.002 used to provide
+lvalue context for the second and subsequent arguments, and perl4 did
+not provide lvalue context to subroutine arguments at all--even though
+arguments were supposedly modifiable in perl4).
+
+ sub test { $_[0] = 1; $_[1] = 2; $_[2] = 3; }
+ &test($foo{'bar'}, $bar{'foo'}, $foo[5]);
+ print join(':', %foo), '|', join(':',%bar), '|', join(':',@foo);
+
+ # perl4 prints: ||
+ # perl5 < 5.002 prints: |foo:2|:::::3
+ # perl5 >= 5.002 prints: bar:1|foo:2|:::::3
+
=item * (Signals)
Barewords that used to look like strings to Perl will now look like subroutine