File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,25 @@ is equivalent to:
100
100
101
101
with the important caveat that EXPR1 is only evaluated once.
102
102
103
+ When used in a longer chain of dereferences, an undef value will short-circuit the entire
104
+ chain, rather than just a single expression:
105
+
106
+ EXPR1 ?-> EXPR2 ?-> EXPR3
107
+
108
+ is equivalent to:
109
+
110
+ ``` perl
111
+ if (defined EXPR1) {
112
+ if (defined EXPR1-> EXPR2) {
113
+ return EXPR1-> EXPR2-> EXPR3
114
+ } else {
115
+ return ()
116
+ }
117
+ } else {
118
+ return () # empty list
119
+ }
120
+ ```
121
+
103
122
## Backwards Compatibility
104
123
105
124
All code with ` ?-> ` currently yields a compile time syntax error, so there
@@ -170,11 +189,8 @@ Expected common uses:
170
189
# my $class = 'SomeClass'; $class->new if defined $class;
171
190
my $class = ' SomeClass' ; $class ?-> new;
172
191
173
- # my $obj = %SomeClass:: ? SomeClass->new : ();
174
- my $obj = SomeClass?-> new; # TBD: see 'Future Scope' below.
175
-
176
- # my @objs = (%NotValid:: ? NotValid->new : (), %Valid:: ? Valid->new : ());
177
- my @objs = ( NotValid?-> new, Valid?-> new ); # @objs == ( ValidObject )
192
+ # defined $aref ? $aref->[0] = 9001 : ()
193
+ $aref ?-> [0] = 9001; # $aref remains undef in the undef case
178
194
```
179
195
180
196
Unusual and edge cases, for comprehension:
You can’t perform that action at this time.
0 commit comments