http://qs321.pair.com?node_id=1218698


in reply to Re: Syntax Perl Version support $c = () = $a =~ /\./g
in thread Syntax Perl Version support $c = () = $a =~ /\./g

jwkrahn, I had to test this, and lo, as you said, tr/.// is about 80% or so faster. I mean, of course, I'd have to run it thousands of times, but there it is, much faster. Thanks for that tip. I'm not clear on what you meant by this:

But note that while the first version will work with strings of any length the second version will only work with characters.

The data is a string of varying lengths, and usually is a decimal number.

  • Comment on Re^2: Syntax Perl Version support $c = () = $a =~ /\./g

Replies are listed 'Best First'.
Re^3: Syntax Perl Version support $c = () = $a =~ /\./g
by mr_mischief (Monsignor) on Jul 17, 2018 at 23:12 UTC
      tr/// (sometimes spelled y///
      Hm, I have been using perl for something like 20 years and even though I have never (as far as I can remember) used tr at all I always knew it existed and what it does.

      "tr" must be short for "translate", but today I learn there is even another version of it - you can trade "tr" for "y" - well who would have guessed.

      As I am (a bit) interested in perl-arcana:

      Does anyone know where this "y" comes from?

      Is is a reference to another language who's users larry wanted to feel at home? Can anyone please enlighten me?

      Many thanks!

        > Is is a reference to another language who's users larry wanted to feel at home?

        Exactly. y/// comes from sed.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,