develooper Front page | perl.perl5.porters | Postings from July 2016

Re: [PATCH] fix warnings in Data::Dumper test on old perl

Thread Previous
From:
Aristotle Pagaltzis
Date:
July 12, 2016 00:21
Subject:
Re: [PATCH] fix warnings in Data::Dumper test on old perl
Message ID:
20160712002058.GA81008@plasmasturm.org
* Graham Knop <haarg@haarg.org> [2016-07-11 23:48]:
> -    no if $] < 5.011, warnings => 'deprecated';
> -    is(scalar(split("\n" => $dumpstr{ar_indent_2})) + 2,
> -        scalar(split("\n" => $dumpstr{ar_indent_3})),
> +    is(scalar(() = $dumpstr{ar_indent_2} =~ /\n/g) + 2,
> +        scalar(() = $dumpstr{ar_indent_3} =~ /\n/g),

These are subtly different. The ()=/\n/g formulation will miss the last
line unless it’s terminated by a newline. Using split/\n/ ignores that,
it counts "a\nb" as 2 lines same as "a\nb\n".

If that difference matters, ()=split can be used to silence the warning
on old perls while still using split.

If the difference does not matter then why not use tr/// instead? That
would simplify the code, since tr/// doesn’t require scalar context:

    is($dumpstr{ar_indent_2} =~ y/\n// + 2,
       $dumpstr{ar_indent_3} =~ y/\n//,
       "Indent(3) runs 2 lines longer than Indent(2)");

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous


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