Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magical variable $. treated as undef [rt.cpan.org #87084] #32

Open
toddr opened this issue May 11, 2017 · 0 comments
Open

magical variable $. treated as undef [rt.cpan.org #87084] #32

toddr opened this issue May 11, 2017 · 0 comments

Comments

@toddr
Copy link
Member

toddr commented May 11, 2017

Migrated from rt.cpan.org#87084 (status was 'open')

Requestors:

From [email protected] on 2013-07-20 03:06:22:

Dump() incorrectly treats $. as undef. Here is a quick example : 

use strict;
use warnings;
use YAML::Syck;

my @lines;
open my $fh, "<", $0 or die $!;
while (<$fh>) {
  push @lines, {bad_num => $., good_num => $.+0, line => $_};
}

print Dump(\@lines);

__END__
Output : 
--- 
- 
  bad_num: ~
  good_num: '1'
  line: "use strict;\n"
- 
  bad_num: ~
  good_num: '2'
  line: "use warnings;\n"
<etc.>

From [email protected] on 2016-02-05 04:11:21:

Hi,

On Fri Jul 19 23:06:22 2013, DAMI wrote:
> Dump() incorrectly treats $. as undef. Here is a quick example : 
> 
> use strict;
> use warnings;
> use YAML::Syck;
> 
> my @lines;
> open my $fh, "<", $0 or die $!;
> while (<$fh>) {
>   push @lines, {bad_num => $., good_num => $.+0, line => $_};
> }
> 
> print Dump(\@lines);
> 
> __END__
> Output : 
> --- 
> - 
>   bad_num: ~
>   good_num: '1'
>   line: "use strict;\n"
> - 
>   bad_num: ~
>   good_num: '2'
>   line: "use warnings;\n"
> <etc.>

I can't see an easy way to make that work safely. The parameters to Dump are passed down to the XS function XS_YAML__Syck_DumpYAML and the C code doesn't know about special Perl variables. Example $$ doesn't work either.

By adding 0 for good_num, Perl is evaluating that before it becomes an argument for Dump, and so that on works.

Gordon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant