in reply to Re: Best practice for reading delimited file
in thread Best practice for reading delimited file

Consider print ${^PREMATCH} if /$/p;, (Perl v5.10+) as using $`...anywhere in a program imposes a considerable performance penalty on all regular expression matches. Source: perlvar.

Replies are listed 'Best First'.
Re^3: Best practice for reading delimited file
by Lennotoecom (Pilgrim) on Oct 16, 2013 at 16:14 UTC
    thank you sir

      You're most welcome, Lennotoecom!

Re^3: Best practice for reading delimited file
by SuicideJunkie (Vicar) on Oct 16, 2013 at 17:06 UTC

    prematch is just a wordier name for $`

    A considerable performance penalty by any other name doth make thine system slow all the same!

    Edit: The documentation apparently doesn't mean what it appears to say.

      prematch is just a wordier name for $`

      $PREMATCH is the same as $` but it's not the same as ${^PREMATCH}:

      * $PREMATCH * $` The string preceding whatever was matched by the last successful pattern match, not counting any matches hidden within a BLOCK or eval enclosed by the current BLOCK. The use of this variable anywhere in a program imposes a considerable performance penalty on all regular expression matches. To avoid this penalty, you can extract the same substring by using @-. Starting with Perl v5.10.0, you can use the /p match flag and the ${^PREMATCH} variable to do the same thing for particular match operations.

      Source: perlvar.

        Ah, nifty!

        Since Perl v5.10.0, you can use the /p match operator flag and the ${^PREMATCH} , ${^MATCH} , and ${^POSTMATCH} variables instead so you only suffer the performance penalties.

        Is that sentence missing a "once" at the end perhaps?