in reply to filenames with ’

I just tried to do this using ord().

I found the ascii code using

$char = '‘'; # a mac smart-quote character print ord($char);
and got 213.

But then I tried to replace it using

$string =~ s/\213//;
and nothing happened. I guess I'm missing something obvious?
--
“Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
M-J D

Replies are listed 'Best First'.
Re: Re: filenames with ’
by hv (Prior) on Feb 17, 2003 at 13:04 UTC

    print ord($char); shows you the decimal value of the character.

    $string =~ s/\213//; attempts to replace the character with octal value 0213, which is decimal 139.

    Try instead with $string =~ s/\325//; and you have a better chance it'll do what you want.

    You don't say why you are doing this, but if the purpose is to clean up a filename to contain only valid characters (however you define "valid" locally), it would be better to invert the sense to remove everything but the valid characters. Then you might end up with something like:

    # allow only letters, digits, underscore and dot (my $cleanfile = $file) =~ s/[^\w.]//g;
    Hugo