Skip Menu |

This queue is for tickets about the String-Substitution CPAN distribution.

Report information
The Basics
Id: 103918
Status: resolved
Priority: 0/
Queue: String-Substitution

People
Owner: Nobody in particular
Requestors: hakon.hagland [...] gmail.com
IKEGAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.002



Subject: Matching a zero with String::Substitution
Date: Thu, 23 Apr 2015 21:03:20 +0200
To: bug-string-substitution [...] rt.cpan.org
From: Håkon Hægland <hakon.hagland [...] gmail.com>
I am trying to match a digit with String::Substitution; it works fine if the digit is not zero. If the digit is zero it substitutes the empty string instead of the digit. For example: use strict; use warnings; use Data::Dump; use String::Substitution; my @data = qw(0 1); for (@data) { my $str = $_; my $regex = qr/(\d)/; my $replace = '$1'; my $result_str = String::Substitution::gsub_copy($str, $regex, $replace); my @m = $str =~ /$regex/g; dd $result_str; dd @m; } The output is: "" 0 1 1 expected output would be: 0 0 1 1 I believe there is a bug on line #95 in the source code https://metacpan.org/source/RWSTAUNER/String-Substitution-1.001/lib/String/Substitution.pm map { ($$_) || '' } ( 1 .. $#- ) it should be map { ($$_) // '' } ( 1 .. $#- ) Note: defined or // not regular or || as in the source.. See also http://stackoverflow.com/questions/29831317/matching-a-zero-with-stringsubstitution Best regards, Håkon Hægland
Show quoted text
> map { ($$_) || '' } ( 1 .. $#- ) > > it should be > > map { ($$_) // '' } ( 1 .. $#- )
The defined-or (//) operator was introduced in 5.10. The following will allow the module to be used on older versions of Perl: map { defined($$_) ? $$_ : '' } ( 1 .. $#- )
Subject: Re: [rt.cpan.org #103918] Matching a zero with String::Substitution
Date: Fri, 24 Apr 2015 22:32:35 -0700
To: bug-String-Substitution [...] rt.cpan.org
From: Randy Stauner <rwstauner [...] cpan.org>
Thanks for reporting. The fix has been applied and a new version released. On Thu, Apr 23, 2015 at 12:07 PM, ikegami via RT <bug-String-Substitution@rt.cpan.org> wrote: Show quoted text
> Queue: String-Substitution > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=103918 > >
>> map { ($$_) || '' } ( 1 .. $#- ) >> >> it should be >> >> map { ($$_) // '' } ( 1 .. $#- )
> > The defined-or (//) operator was introduced in 5.10. The following will allow the module to be used on older versions of Perl: > > map { defined($$_) ? $$_ : '' } ( 1 .. $#- ) >