File tree Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Original file line number Diff line number Diff line change 2
2
use strict;
3
3
use feature ' say' ;
4
4
5
- say ' 1..10 ' ;
5
+ say ' 1..18 ' ;
6
6
7
7
my $x = " abcd" ;
8
8
if (substr ($x ,1,1) ne " b" ) {
@@ -51,3 +51,52 @@ say "ok 9 # $tail";
51
51
print ' not ' if $z ne ' tr' ;
52
52
say ' ok 10' ;
53
53
54
+
55
+ # interpolation
56
+
57
+ my $v = 123;
58
+ my $r = " -$v -" ;
59
+ print ' not ' if $r ne ' -123-' ; say ' ok 11 - scalar interpolation' ;
60
+
61
+ my @v = (234, 567);
62
+ $r = " -$v [1]-" ;
63
+ print ' not ' if $r ne ' -567-' ; say ' ok 12 - array element interpolation' ;
64
+
65
+ $r = " -${v[1]}-" ;
66
+ print ' not ' if $r ne ' -567-' ; say ' ok 13 - array element interpolation' ;
67
+
68
+ $r = " -@v -" ;
69
+ print ' not ' if $r ne ' -234 567-' ; say ' ok 14 - array interpolation' ;
70
+
71
+ my %v = (xyz => 234, abc => 567);
72
+ $r = " -$v {xyz}-" ;
73
+ print ' not ' if $r ne ' -234-' ; say ' ok 15 - hash element interpolation' ;
74
+
75
+ $r = " -${v{xyz}}-" ;
76
+ print ' not ' if $r ne ' -234-' ; say ' ok 16 - hash element interpolation' ;
77
+
78
+ $v = { xyz => 123, abc => 567 };
79
+ $r = " -$v ->{xyz}-" ;
80
+ print ' not ' if $r ne ' -123-' ; say " ok 17 - hash deref interpolation - $r " ;
81
+
82
+ # {
83
+ # no strict 'refs';
84
+ # # Can't use bareword ("v") as a HASH ref while "strict refs" in use
85
+ # # Global symbol "%v" requires explicit package name
86
+ # $r = "-${v->{xyz}}-";
87
+ # print 'not ' if $r ne '-234-'; say 'ok 18 - hash deref interpolation';
88
+ # }
89
+
90
+ $v = [ 123, 567, 890 ];
91
+ $r = " -$v ->[2]-" ;
92
+ print ' not ' if $r ne ' -890-' ; say " ok 18 - array deref interpolation - $r " ;
93
+
94
+ # {
95
+ # no strict 'refs';
96
+ # # Can't use bareword ("v") as a HASH ref while "strict refs" in use
97
+ # # Global symbol "@v" requires explicit package name
98
+ # $r = "-${v->[2]}-";
99
+ # print 'not ' if $r ne '-890-'; say 'ok 18 - array deref interpolation';
100
+ # }
101
+
102
+
You can’t perform that action at this time.
0 commit comments