Perl6 search then replace with output of subroutineHow to replace a character by a newline in VimHow to replace all occurrences of a string in JavaScriptRegular expression search replace in Sublime Text 2Perl6: Capturing Windows newline in a string with regexType coercion in Perl6 class attributeHow to read gz file line by line in Perl6Cannot import Perl5 module using Inline::Perl5 into Perl6Perl6: getting array ref for Perl5 ModulePerl6: large gzipped files read line by linePerl6 crashes, “left argument in overloaded package Perl6::Object”

Why is the marginal distribution/marginal probability described as "marginal"?

How to check if comma list is empty?

History of the Frobenius Endomorphism?

Does this "yield your space to an ally" rule my 3.5 group uses appear anywhere in the official rules?

Why is Drogon so much better in battle than Rhaegal and Viserion?

How to rename multiple files in a directory at the same time

tikz drawing rectangle discretized with triangle lattices and its centroids

Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?

the correct order of manual install WP and SSL on server

What do the "optional" resistor and capacitor do in this circuit?

Do people who work at research institutes consider themselves "academics"?

Slice a list based on an index and items behind it in python

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

Why do galaxies collide?

Understanding Python syntax in lists vs series

Can anyone give me examples of the relative-determinative 'which'?

Which creature is depicted in this Xanathar's Guide illustration of a war mage?

Assembly writer vs compiler

​Cuban​ ​Primes

Was the dragon prowess intentionally downplayed in S08E04?

Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?

Does the Rogue's Reliable Talent feature work for thieves' tools, since the rogue is proficient in them?

Getting a similar picture (colours) on Manual Mode while using similar Auto Mode settings (T6 and 40D)



Perl6 search then replace with output of subroutine


How to replace a character by a newline in VimHow to replace all occurrences of a string in JavaScriptRegular expression search replace in Sublime Text 2Perl6: Capturing Windows newline in a string with regexType coercion in Perl6 class attributeHow to read gz file line by line in Perl6Cannot import Perl5 module using Inline::Perl5 into Perl6Perl6: getting array ref for Perl5 ModulePerl6: large gzipped files read line by linePerl6 crashes, “left argument in overloaded package Perl6::Object”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








13















I've combed the docs but I can't seem to find how to do this in perl6.



In perl5 I would have done (just an example):



sub func ... 

$str =~ s/needle/func($1)/e;


i.e. to replace 'needle' with the output of a call to 'func'










share|improve this question






























    13















    I've combed the docs but I can't seem to find how to do this in perl6.



    In perl5 I would have done (just an example):



    sub func ... 

    $str =~ s/needle/func($1)/e;


    i.e. to replace 'needle' with the output of a call to 'func'










    share|improve this question


























      13












      13








      13








      I've combed the docs but I can't seem to find how to do this in perl6.



      In perl5 I would have done (just an example):



      sub func ... 

      $str =~ s/needle/func($1)/e;


      i.e. to replace 'needle' with the output of a call to 'func'










      share|improve this question
















      I've combed the docs but I can't seem to find how to do this in perl6.



      In perl5 I would have done (just an example):



      sub func ... 

      $str =~ s/needle/func($1)/e;


      i.e. to replace 'needle' with the output of a call to 'func'







      regex replace perl6 evaluation string-substitution






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 10 at 12:57









      raiph

      12.8k22445




      12.8k22445










      asked May 10 at 12:09









      iPherianiPherian

      669824




      669824






















          2 Answers
          2






          active

          oldest

          votes


















          9














          Ok so we'll start by making a function that just returns our input repeated 5 times



          sub func($a) $a x 5 ;


          Make our string



          my $s = "Here is a needle";


          And here's the replace



          $s ~~ s/"needle"/func($/)/;


          Couple of things to notice. As we just want to match a string we quote it. And our output is effectively a double quoted string so to run a function in it we use . No need for the e modifier as all strings allow for that kind of escaping.



          The docs on substitution mention that the Match object is put in $/ so we pass that to our function. In this case the Match object when cast to a String just returns the matched string. And we get as our final result.



          Here is a needleneedleneedleneedleneedle





          share|improve this answer


















          • 1





            "needle" can of course be an actual regex and it works fine with that too.

            – Scimon
            May 10 at 12:31






          • 1





            Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

            – raiph
            May 10 at 12:48



















          12














          There is no e modifier in Perl 6; instead, the right hand part is treated like a double-quoted string. The most direct way to call a function is therefore to stick an & before the function name and use function call interpolation:



          # An example function
          sub func($value)
          $value.uc


          # Substitute calling it.
          my $str = "I sew with a needle.";
          $str ~~ s/(needle)/&func($0)/;
          say $str;


          Which results in "I sew with a NEEDLE.". Note also that captures are numbered from 0 in Perl 6, not 1. If you just want the whole captured string, pass $/ instead.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56077459%2fperl6-search-then-replace-with-output-of-subroutine%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            9














            Ok so we'll start by making a function that just returns our input repeated 5 times



            sub func($a) $a x 5 ;


            Make our string



            my $s = "Here is a needle";


            And here's the replace



            $s ~~ s/"needle"/func($/)/;


            Couple of things to notice. As we just want to match a string we quote it. And our output is effectively a double quoted string so to run a function in it we use . No need for the e modifier as all strings allow for that kind of escaping.



            The docs on substitution mention that the Match object is put in $/ so we pass that to our function. In this case the Match object when cast to a String just returns the matched string. And we get as our final result.



            Here is a needleneedleneedleneedleneedle





            share|improve this answer


















            • 1





              "needle" can of course be an actual regex and it works fine with that too.

              – Scimon
              May 10 at 12:31






            • 1





              Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

              – raiph
              May 10 at 12:48
















            9














            Ok so we'll start by making a function that just returns our input repeated 5 times



            sub func($a) $a x 5 ;


            Make our string



            my $s = "Here is a needle";


            And here's the replace



            $s ~~ s/"needle"/func($/)/;


            Couple of things to notice. As we just want to match a string we quote it. And our output is effectively a double quoted string so to run a function in it we use . No need for the e modifier as all strings allow for that kind of escaping.



            The docs on substitution mention that the Match object is put in $/ so we pass that to our function. In this case the Match object when cast to a String just returns the matched string. And we get as our final result.



            Here is a needleneedleneedleneedleneedle





            share|improve this answer


















            • 1





              "needle" can of course be an actual regex and it works fine with that too.

              – Scimon
              May 10 at 12:31






            • 1





              Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

              – raiph
              May 10 at 12:48














            9












            9








            9







            Ok so we'll start by making a function that just returns our input repeated 5 times



            sub func($a) $a x 5 ;


            Make our string



            my $s = "Here is a needle";


            And here's the replace



            $s ~~ s/"needle"/func($/)/;


            Couple of things to notice. As we just want to match a string we quote it. And our output is effectively a double quoted string so to run a function in it we use . No need for the e modifier as all strings allow for that kind of escaping.



            The docs on substitution mention that the Match object is put in $/ so we pass that to our function. In this case the Match object when cast to a String just returns the matched string. And we get as our final result.



            Here is a needleneedleneedleneedleneedle





            share|improve this answer













            Ok so we'll start by making a function that just returns our input repeated 5 times



            sub func($a) $a x 5 ;


            Make our string



            my $s = "Here is a needle";


            And here's the replace



            $s ~~ s/"needle"/func($/)/;


            Couple of things to notice. As we just want to match a string we quote it. And our output is effectively a double quoted string so to run a function in it we use . No need for the e modifier as all strings allow for that kind of escaping.



            The docs on substitution mention that the Match object is put in $/ so we pass that to our function. In this case the Match object when cast to a String just returns the matched string. And we get as our final result.



            Here is a needleneedleneedleneedleneedle






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 10 at 12:20









            ScimonScimon

            2,1971312




            2,1971312







            • 1





              "needle" can of course be an actual regex and it works fine with that too.

              – Scimon
              May 10 at 12:31






            • 1





              Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

              – raiph
              May 10 at 12:48













            • 1





              "needle" can of course be an actual regex and it works fine with that too.

              – Scimon
              May 10 at 12:31






            • 1





              Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

              – raiph
              May 10 at 12:48








            1




            1





            "needle" can of course be an actual regex and it works fine with that too.

            – Scimon
            May 10 at 12:31





            "needle" can of course be an actual regex and it works fine with that too.

            – Scimon
            May 10 at 12:31




            1




            1





            Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

            – raiph
            May 10 at 12:48






            Hi Scimon. Nice quick clean answer. "needle" could also be needle, without the quotes. Presumably you chose/prefer to quote it for clarity?

            – raiph
            May 10 at 12:48














            12














            There is no e modifier in Perl 6; instead, the right hand part is treated like a double-quoted string. The most direct way to call a function is therefore to stick an & before the function name and use function call interpolation:



            # An example function
            sub func($value)
            $value.uc


            # Substitute calling it.
            my $str = "I sew with a needle.";
            $str ~~ s/(needle)/&func($0)/;
            say $str;


            Which results in "I sew with a NEEDLE.". Note also that captures are numbered from 0 in Perl 6, not 1. If you just want the whole captured string, pass $/ instead.






            share|improve this answer



























              12














              There is no e modifier in Perl 6; instead, the right hand part is treated like a double-quoted string. The most direct way to call a function is therefore to stick an & before the function name and use function call interpolation:



              # An example function
              sub func($value)
              $value.uc


              # Substitute calling it.
              my $str = "I sew with a needle.";
              $str ~~ s/(needle)/&func($0)/;
              say $str;


              Which results in "I sew with a NEEDLE.". Note also that captures are numbered from 0 in Perl 6, not 1. If you just want the whole captured string, pass $/ instead.






              share|improve this answer

























                12












                12








                12







                There is no e modifier in Perl 6; instead, the right hand part is treated like a double-quoted string. The most direct way to call a function is therefore to stick an & before the function name and use function call interpolation:



                # An example function
                sub func($value)
                $value.uc


                # Substitute calling it.
                my $str = "I sew with a needle.";
                $str ~~ s/(needle)/&func($0)/;
                say $str;


                Which results in "I sew with a NEEDLE.". Note also that captures are numbered from 0 in Perl 6, not 1. If you just want the whole captured string, pass $/ instead.






                share|improve this answer













                There is no e modifier in Perl 6; instead, the right hand part is treated like a double-quoted string. The most direct way to call a function is therefore to stick an & before the function name and use function call interpolation:



                # An example function
                sub func($value)
                $value.uc


                # Substitute calling it.
                my $str = "I sew with a needle.";
                $str ~~ s/(needle)/&func($0)/;
                say $str;


                Which results in "I sew with a NEEDLE.". Note also that captures are numbered from 0 in Perl 6, not 1. If you just want the whole captured string, pass $/ instead.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 10 at 13:03









                Jonathan WorthingtonJonathan Worthington

                10.9k13257




                10.9k13257



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56077459%2fperl6-search-then-replace-with-output-of-subroutine%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form