Simply putting '...' or q(...) around a string is not sufficient to
quote it properly, allowing this sort of ‘fun’:
$ perl -l -MO=Deparse -e'BEGIN{$^H{"'\''.'\''"} = "um);\n exit("}print'
BEGIN { $/ = "\n"; $\ = "\n"; }
sub BEGIN {
$^H{q['.']} = "um);\n exit(";
}
BEGIN {
$^H{''.''} = q(um);
exit();
}
print $_;
-e syntax OK
And B::Deparse already has a facility for quoting strings, so why
not use it?
for my $key (keys %$to) {
next if $ignored_hints{$key};
if (!exists $from->{$key} or $from->{$key} ne $to->{$key}) {
- push @decls, qq(\$^H{'$key'} = )
- . (defined $to->{$key} ? qq(q($to->{$key})) : 'undef')
+ push @decls,
+ qq(\$^H{) . single_delim("q", "'", $key) . qq(} = )
+ . (
+ defined $to->{$key}
+ ? single_delim("q", "'", $to->{$key})
+ : 'undef'
+ )
. qq(;);
}
}
}
print $_;
}
+BEGIN { $^H{q[']} = '('; }
+print $_;