Skip to content

[doc] Add dynamic regexp modifier example #18387

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

Closed
jidanni opened this issue Dec 6, 2020 · 5 comments
Closed

[doc] Add dynamic regexp modifier example #18387

jidanni opened this issue Dec 6, 2020 · 5 comments

Comments

@jidanni
Copy link
Member

jidanni commented Dec 6, 2020

perlop and perlre explain everything in extreme detail, but never seem
to give an example of how to write the modifier of

/bla/i

dynamically.

Nope,

my $modifier='i';
/bla/$modifier

won't work.

Sure, one could use 'eval', but that would end up eval'ing the /bla/
part too.

So please add an example to those documentation pages.

Or mention the only way is to do

if($modifier eq 'i'){
... /bla/i ...
elsif($modifier eq 'ia'){
    /bla/ia ...

etc. Thanks.

Hmmm, reminds me of sprintf:

    You can also get the precision from the next argument using
     ".*", or from a specified argument (e.g., with ".*2$"):
@Grinnz
Copy link
Contributor

Grinnz commented Dec 6, 2020

@Grinnz
Copy link
Contributor

Grinnz commented Dec 6, 2020

Alternatively, https://perldoc.perl.org/re#'/flags'-mode

@jidanni
Copy link
Member Author

jidanni commented Dec 7, 2020

That's all great news.

But please be sure to say something about it within the Modifiers section,

$ egrep ^=head2\|flexible /usr/share/perl/5.32.0/pod/perlre.pod
=head2 The Basics
=head2 Modifiers
=head2 Regular Expressions
=head2 Quoting metacharacters
=head2 Extended Patterns
    # more flexible:
=head2 Backtracking

Otherwise the user will have given up long before making it down to that section.

So at the bottom of the Modifiers sections, say "Modifiers can also be
given dynamically. See ..."

Thanks!

@jkeenan
Copy link
Contributor

jkeenan commented Jan 15, 2021

I'm not sure I see a real need for this addition to the documentation, but if others want it, #18481 should suffice.

Thank you very much.
Jim Keenan

jkeenan added a commit that referenced this issue Jan 31, 2021
@jkeenan
Copy link
Contributor

jkeenan commented Jan 31, 2021

Handled by a19f662; closing ticket.

Thank you very much.
Jim Keenan

@jkeenan jkeenan closed this as completed Jan 31, 2021
Corion pushed a commit to Corion/perl5 that referenced this issue Jun 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants