in reply to Re: More efficient way to truncate long strings of the same character
in thread More efficient way to truncate long strings of the same character

map "(?<=$_{3})$_+", should be map "(?<=${_}{3})$_+",.


Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^3: More efficient way to truncate long strings of the same character
by ikegami (Patriarch) on Oct 30, 2008 at 23:41 UTC

    It's not necessary.

    >perl -e"$_='a'; print qr/$_{3}/" (?-xism:a{3})

    And beyond being unnecessary, it will never help either. If you were to do ${_}{...} to prevent $_{...} from beint treated as a hash element, it still wouldn't do what you want. See Re: Of scalars, hashes, quantifiers, and regexen.

      So when I run:

      use strict; use warnings; my ($ikegamiRe1) = map qr/$_/, join '|', map "(?<=$_{3})$_+", map quot +emeta, 1 .. 9;

      I should ignore:

      Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4. Use of uninitialized value in concatenation (.) or string at noname.pl + line 4.

      Update: Oh, and here's an interesting result:

      use strict; #use warnings; my $str = join '|', map "(?<=${_}{3})$_+", 1 .. 2; print $str, "\n"; $str = join '|', map "(?<=$_{3})$_+", 1 .. 2; print $str;

      Prints:

      (?<=1{3})1+|(?<=2{3})2+ (?<=)1+|(?<=)2+

      Perl reduces RSI - it saves typing
        Oh shoot, that's a string literal and not a regexp literal! Fixed.