summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-12-31 23:24:57 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-12-31 23:34:49 -0800
commit69974ce61d7459da5eda22eb31d730128757db37 (patch)
tree77493eb569a84e4a683da7951e720ba3c5ccb322 /t
parente38523840a8a9be645c93d91b9cd796de84f508c (diff)
downloadperl-69974ce61d7459da5eda22eb31d730128757db37.tar.gz
[perl #103492] Give lvalue cx to (s)printf args
Or potential lvalue context, like function calls. The %n format code’s existence renders these two very much like func- tion calls, as they can modify their arguments. This allows sprintf("...%n", substr ...) to work.
Diffstat (limited to 't')
-rw-r--r--t/io/print.t7
-rw-r--r--t/op/sprintf.t1
2 files changed, 7 insertions, 1 deletions
diff --git a/t/io/print.t b/t/io/print.t
index 321eb1e85b..00ee7fb591 100644
--- a/t/io/print.t
+++ b/t/io/print.t
@@ -10,7 +10,7 @@ BEGIN {
use strict 'vars';
-print "1..21\n";
+print "1..23\n";
my $foo = 'STDOUT';
print $foo "ok 1\n";
@@ -66,3 +66,8 @@ if (!exists &Errno::EBADF) {
map print(+()), ('')x68;
print "ok 21\n";
}
+
+# printf with %n
+my $n = "abc";
+printf "ok 22%n - not really a test; just printing\n", substr $n,1,1;
+print "not " x ($n ne "a5c") . "ok 23 - printf with %n (got $n)\n";
diff --git a/t/op/sprintf.t b/t/op/sprintf.t
index b8c8bced4c..de1079e2d7 100644
--- a/t/op/sprintf.t
+++ b/t/op/sprintf.t
@@ -436,6 +436,7 @@ __END__
>%l< >''< >%l INVALID<
>%m< >''< >%m INVALID<
>%s< >sprintf('%%n%n %d', $n, $n)< >%n 2< >Slight sneakiness to test %n<
+>%s< >$n="abc"; sprintf(' %n%s', substr($n,1,1), $n)< > a1c< >%n w/magic<
>%o< >2**32-1< >37777777777<
>%+o< >2**32-1< >37777777777<
>%#o< >2**32-1< >037777777777<