Skip to content

[doc] Add dynamic regexp modifier example #18387

Closed
@jidanni

Description

@jidanni

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$"):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions