in reply to simplifying substitution

Maybe this?

$all =~ s/  ([1-9][0-9]) /  $1\t\t/g;

Replies are listed 'Best First'.
Re^2: simplifying substitution
by Polyglot (Chaplain) on Mar 08, 2021 at 13:00 UTC

    Maybe my perl version is different, but I can never get away with using actual spaces like that on the match side--I'd have to represent them...something like this:

    $all =~ s/([ ]{2}[1-9][0-9])[ ]/$1\t\t/g;

    If running strictly on English and there were no possibilities or no issue with encountering numbers like '04' which had to be handled differently, the code could be a mite simpler:

    $all =~ s/([ ]{2}\d\d)[ ]/$1\t\t/g;

    Blessings,

    ~Polyglot~

      Without the /x modifier, a space should match literally. What's the output of
      perl -lwe 'print qq( $]) =~ s/ /v/r'
      (use double quotes instead on MSWin)

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        I get this output from that command (I'm not on Windows):

        Bareword found where operator expected at -e line 1, near "s/ /v/r" Unquoted string "r" may clash with future reserved word at -e line 1. Can't modify string in substitution (s///) at -e line 1, near "s/ /v/r " syntax error at -e line 1, near "s/ /v/r " Execution of -e aborted due to compilation errors.

        When I check the version, I get this:

        perl -v This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-th +read-multi-2level (with 2 registered patches, see perl -V for more detail) Copyright 1987-2010, Larry Wall

        Blessings,

        ~Polyglot~

      Thanks to all of you, for your contributions! Since my script will be dealing strictly with English text, I decided to try "$all =~ s/( {2}\d\d) /$1\t\t/g;" first, and it seems to do the trick!
      Aloha, and stay safe!