Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: tr///c doesn't seem to work as I expect

by romandas (Pilgrim)
on Sep 04, 2009 at 20:38 UTC ( #793590=note: print w/ replies, xml ) Need Help??


in reply to Re: tr///c doesn't seem to work as I expect
in thread tr///c doesn't seem to work as I expect

Wow.. maybe. Is that a valid range? I thought it meant '-' itself. That must be it.


Comment on Re^2: tr///c doesn't seem to work as I expect
Re^3: tr///c doesn't seem to work as I expect
by james2vegas (Chaplain) on Sep 04, 2009 at 20:42 UTC
    From perlop:
    The character "-" is treated specially and therefore "\-" is treated +as a literal "-".


    The - indicates a range.

    if($data !~ /^[\ \-\~\007\012\015\035\036\037]*$/) { $data =~ tr/[\ \-\~\007\012\015\035\036\037]/ /cs; }
    is probably what you need.
      Thanks. Given the rest of the code (not shown), actually the range makes a lot more sense. It might not be 'correct', but I at least understand what's going on now. :)

      One small point:

      In the  tr operator, the  [ and  ] characters have no special meaning. (In a 'normal' regex, they define a character set.) In the expressison (as taken from the OP)
          $data =~ tr/[\ -\~\007\012\015\035\036\037]/ /cs;
      the  [ and  ] characters simply represent themselves. This has no effect in this particular case, however, since these characters are also included in the range  \ -\~ that includes, IIRC, all printable ASCII characters. (I think a space qualifies as a 'printable' character.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://793590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2015-07-04 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls