develooper Front page | perl.perl5.porters | Postings from June 2008

[perl #3534] It's not a bug, it's documented behaviour...

From:
renee.baecker
Date:
June 7, 2008 11:40
Subject:
[perl #3534] It's not a bug, it's documented behaviour...
Message ID:
20080607184044.27E511200F3@rserv16.sitepush.net
Perl thinks, that you are constructing an anonymous hash. You just need
to put a ';' before the loop label and everything works...

This is a known behaviour (see perldoc perlref)

As it is documented, I think this ticket should be closed...

use strict;
use warnings;

my($code, $sort_code, $sort_code_template, $test);

print "1..2\n";

$sort_code_template = <<'EOF';
my(@foo) = (1, 3, 2);

sort {
<CODE> # <--- all is well if we place some valid code here
;POINTLESS_LOOP: foreach (1..10) {}
$a <=> $b;
} @foo;
EOF

$test = 1;

CODE_FRAGMENT:
foreach $code ('', '1;') {
$sort_code = $sort_code_template;
$sort_code =~ s/<CODE>/$code/;
eval $sort_code;
print STDERR $@ if $@;
print $@ ? "not ok $test\n" : "ok $test\n";
$test++;
}


(note the ';' before the label)

reneeb@reneeb-desktop:~/bugs$ perl 3534.pl
1..2
ok 1
ok 2

Cheers,
Renée






nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About