|
Boost : |
From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2005-12-08 23:41:50
On 12/6/05, Eric Niebler <eric_at_[hidden]> wrote:
>
> Boris Kolpackov wrote:
> > John,
> >
> > "John Maddock" <john_at_[hidden]> writes:
> >
> >
> >>>Following the logic above it will match all single letters in the
> >>>string,
> >>>no?
> >>
> >>No, because of the trailing $.
> >
> >
> > The original expression had trailing $ as well but it didn't help much,
> > did it?
> >
> > So what's the verdict, is this a bug or a feature?
> >
>
>
> Feature. Perl has the same behavior:
>
> $str = 'test.cidl';
> $str =~ s/(\.(idl|cidl|cdl))?$/E.idl/g;
> print "$str\n";
>
> ... prints:
>
> testE.idlE.idl
Indeed it does.
If the user wants only one substitution, I'd say the use of /g, which allows
s/// to match multiple times, is the central mistake.
** With /g
$ perl -le '($a = "test.cidl") =~ s/(\.(c?idl|cdl))?$/E.idl/g; print $a'
testE.idlE.idl
** Without
$ perl -le '($a = "test.cidl") =~ s/(\.(c?idl|cdl))?$/E.idl/; print $a'
testE.idl
-- Caleb Epstein caleb dot epstein at gmail dot com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk