in reply to Re: How to make this substitutions without splitting the strings?
in thread How to make this substitutions without splitting the strings?

Thank you very much, it works like a charm...
Can you please tell me what does this line:
(my $mask = $s1) =~ tr{-\x00-,.-\xff}{\x00\xff};
do? Also, which is the null character?
Thanks again!
  • Comment on Re^2: How to make this substitutions without splitting the strings?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to make this substitutions without splitting the strings?
by AnomalousMonk (Archbishop) on Jul 28, 2014 at 13:56 UTC
    ... what does this line:

    (my $mask = $s1) =~ tr{-\x00-,.-\xff}{\x00\xff};

    It copies the string  $s1 to the new lexical  $mask while simultaneously translating the characters of  $s1 with the  tr/// function. If you have Perl version 5.14+, you can simplify this statement somewhat by using the  /r modifier:
        my $mask = $s1 =~ tr{-\x00-,.-\xff}{\x00\xff}r;
    See  tr/// in the Quote-Like Operators section in perlop.

    ... which is the null character?

    It is the  \0 character (or byte), hex 0x00, octal 000 (also decimal 0). (Update: Along with its cousin 0xff, it's very useful for creating bit-masks for strings.)