summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-08-06 09:48:07 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-08-06 14:04:03 -0700
commit64a408986cf3da7615062d0778e28cfa24288618 (patch)
tree1043275c237f051d795efb8b151b5bb0bcaddc89 /t
parenteaf6a13dc1ee199aebc2ca608507bab3b8244655 (diff)
downloadperl-64a408986cf3da7615062d0778e28cfa24288618.tar.gz
Nested formats
Are nested formats a good idea? Probably not. But the only rea- son they don’t work is that the parser becomes confused and loses track of where it is. And it would be nice to have some consistency. I can put sub defini- tions inside a format: format = @ ;sub foo { bar } . and: format = @ { sub foo { bar } } . so why not these? format foo = @ ;format bar = @ . . format foo = @ { format bar = @ . } . In perl 5.17.2 and earlier, you can nest formats, but, due to the parser being confused, the outer format must be terminated with } instead of a dot. That stopped working with commit 7c70caa5333. format = @<<<<<<<<<<<<<<< "Just another"; format STDERR = @<<<<<<<<<<<<<<< "Perl hacker" . } write; select STDERR; write;
Diffstat (limited to 't')
-rw-r--r--t/op/write.t20
1 files changed, 19 insertions, 1 deletions
diff --git a/t/op/write.t b/t/op/write.t
index 17b8869eb5..2d5b0ac79a 100644
--- a/t/op/write.t
+++ b/t/op/write.t
@@ -61,7 +61,7 @@ for my $tref ( @NumTests ){
my $bas_tests = 20;
# number of tests in section 3
-my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 4;
+my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 5;
# number of tests in section 4
my $hmb_tests = 35;
@@ -1017,6 +1017,24 @@ format =
;1
|, 'format = ... } is not allowed';
+open(NEST, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+format NEST =
+@<<<
+{
+ my $birds = "birds";
+ local *NEST = *BIRDS{FORMAT};
+ write NEST;
+ format BIRDS =
+@<<<<<
+$birds;
+.
+ "nest"
+}
+.
+write NEST;
+close NEST or die "Could not close: $!";
+is cat('Op_write.tmp'), "birds\nnest\n", 'nested formats';
+
#############################
## Section 4