Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed the reference operator

  • Loading branch information...
commit 71247ab7ef3afc0d229f5b56c89881218fdeeffd 1 parent cf8e3a6
@cowens authored
Showing with 19 additions and 12 deletions.
  1. +19 −12 perlopref.pod
View
31 perlopref.pod
@@ -841,24 +841,28 @@ This belongs to L<perlop/Symbolic Unary Operators>.
=head3 Description
-This is the backslash operator (AKA the reference operator). It creates a
-reference to X.
+This is the backslash operator (AKA the reference operator). If X is a
+variable, function, or a scalar literal, then it creates a reference to X.
+If X is a list, then it creates a list of references to the items in the
+list.
=head3 Example
- my $s = 5;
- my $sref = \$s; #$sref is now a reference to $s
- $$sref = 6; #$s is now 6
+ my $c = \1024; #$c is now a reference to the literal 1024
- my @a = (1, 2, 3);
- my $aref = \@a; #$aref is now a reference to @a
- $aref->[0] = 5; #@a is now (5, 2, 3)
+ my $s = 5;
+ my $sref = \$s; #$sref is now a reference to $s
+ $$sref = 6; #$s is now 6
+
+ my @a = (1, 2, 3);
+ my $aref = \@a; #$aref is now a reference to @a
+ $aref->[0] = 5; #@a is now (5, 2, 3)
push @$aref, 6; #@a is now (5, 2, 3, 6)
- my %h = (a => 1, b => 2, c => 3);
- my $href = \%h; #$href is now a reference to %h
- $href->{b} = 5; #%h is now (a => 1, b => 5, c => 3)
- my @keys = keys %$href; #@keys is now ("a", "b", "c")
+ my %h = (a => 1, b => 2, c => 3);
+ my $href = \%h; #$href is now a reference to %h
+ $href->{b} = 5; #%h is now (a => 1, b => 5, c => 3)
+ my @keys = keys %$href; #@keys is now ("a", "b", "c")
sub foo {
return join "|", @_;
@@ -867,6 +871,9 @@ reference to X.
my $x = $coderef->(1, 2, 3); #$x is now "1|2|3";
my $y = &$coderef(4, 5, 6); #$y is now "4|5|6";
+ #@refs now holds references to $s, @a, and %h
+ my @refs = \($s, @a, %h);
+
=head3 See also
L<< /X -> Y >> in L<perlopref>, L<perlreftut>, and L<perlref>
Please sign in to comment.
Something went wrong with that request. Please try again.