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

.subst/.subst-mutate with :g do not set $/ to all the matches #6043

Closed
p6rt opened this issue Feb 1, 2017 · 4 comments
Closed

.subst/.subst-mutate with :g do not set $/ to all the matches #6043

p6rt opened this issue Feb 1, 2017 · 4 comments
Labels

Comments

@p6rt
Copy link

@p6rt p6rt commented Feb 1, 2017

Migrated from rt.perl.org#130688 (status was 'resolved')

Searchable as RT130688$

@p6rt
Copy link
Author

@p6rt p6rt commented Feb 1, 2017

From @zoffixznet

When the :g adverb is used with .match, s/// or, S///, the $/ contains a list of match objects
for each of the matches made during matching/substitution​:

  <ZoffixW> m​: 'fog'.match​: :g, /./; say $/
  <camelia> rakudo-moar 97359a​: OUTPUT«(「f」 「o」 「g」)␤»
  <ZoffixW> m​: S​:g/./x/ given $ = 'fog'; say $/
  <camelia> rakudo-moar 97359a​: OUTPUT«(「f」 「o」 「g」)␤»
  <ZoffixW> m​: s​:g/./x/ given $ = 'fog'; say $/
  <camelia> rakudo-moar 97359a​: OUTPUT«(「f」 「o」 「g」)␤»

However, the .subst/.subst-mutate methods only return the last match made and not all of them​:

  <ZoffixW> m​: 'fog'.subst​: :g, /./, 'x'; say $/
  <camelia> rakudo-moar 97359a​: OUTPUT«「g」␤»
  <ZoffixW> m​: ($ = 'fog').subst​: :g, /./, 'x'; say $/
  <camelia> rakudo-moar 97359a​: OUTPUT«「g」␤»

I briefly looked at the code and they seem to call match + APPLY-MATCHES just like S/// ops do.
No idea why the $/ ends up with just the final match.

Loading

@p6rt
Copy link
Author

@p6rt p6rt commented Mar 22, 2017

From @zoffixznet

Also affects :x and :nth modifiers

<Zoffix> m​: 'mmmmmmm'.subst​: :x(1..3), /m/, 'g'; say WHAT $/
<camelia> rakudo-moar 6a77cd​: OUTPUT​: «(Match)␤»
<Zoffix> m​: 'mmmmmmm'.subst​: :nth(1..3), /m/, 'g'; say WHAT $/
<camelia> rakudo-moar 6a77cd​: OUTPUT​: «(Match)␤»

Loading

@p6rt
Copy link
Author

@p6rt p6rt commented Mar 8, 2018

From @zoffixznet

On Wed, 22 Mar 2017 13​:58​:22 -0700, cpan@​zoffix.com wrote​:

Also affects :x and :nth modifiers

<Zoffix> m​: 'mmmmmmm'.subst​: :x(1..3), /m/, 'g'; say WHAT $/
<camelia> rakudo-moar 6a77cd​: OUTPUT​: «(Match)␤»
<Zoffix> m​: 'mmmmmmm'.subst​: :nth(1..3), /m/, 'g'; say WHAT $/
<camelia> rakudo-moar 6a77cd​: OUTPUT​: «(Match)␤»

Thank you for the report. This is now fixed.

Fix​: rakudo/rakudo@874fcdd
Test​: Raku/roast@af02dd6

Loading

@p6rt p6rt closed this Mar 8, 2018
@p6rt
Copy link
Author

@p6rt p6rt commented Mar 8, 2018

@zoffixznet - Status changed from 'new' to 'resolved'

Loading

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant