Re: Convert potion of string to Octal




Bill H wrote:
> Paul Lalli wrote:
> > Bill H wrote:
> > > ...
> > > > s/ ( [^[:ascii:]] ) / sprintf '\%o', ord $1 /gex;
> > > >
> > >
> > > Thanks for the quick response but that converts all the characters - is
> > > there way for it to only do those with ascii values over 127?
> > >
> > > I did a quick test of it using:
> > >
> > > $a = "The next character is octal ü" ;
> > > $a =~ s/ ( [^[:ascii:]] ) / sprintf '\%o', ord $1 /gex;
> > > print $a;
> >
> > You did something wrong. When I run those three lines of code - by
> > copy and pasting your post - I get:
> > The next character is octal \374
> >
> > What output did you obtain?
>
> Every character was converted to the \octal value. I replaced the
> ^[:ascii:] with the part of the code you gave [\x80-\xFF] and it worked
> fine after that.

Your expression looks ok but you'd see a mass conversion if you
inserted
a space between the [ and ^ like this:

s/ ( [ ^[:ascii:] ] ) / sprintf '\%o', ord $1 /gex;
|
|
space

The regex 'x' modifier ignores (most) whitespace but not within a
character
class.

hth,
--
Charles DeRykus

.



Relevant Pages

  • Re: Convert potion of string to Octal
    ... > Bill H wrote: ... >> Paul Lalli wrote: ... >> Every character was converted to the \octal value. ... > Your expression looks ok but you'd see a mass conversion if you ...
    (comp.lang.perl.misc)
  • Re: Need line count explanation help
    ... currently involved in discussing with doctors wife as my bill was higher ... >> doing my margins and doing gross lines. ... >> She still is horrified I count every character. ... I said I DO BILL LINES but I figure by characters not gross ...
    (sci.med.transcription)
  • Re: assigning variables in e.g. an if ....
    ... Bill H wrote: ... echo $i; ... So in the first example the 'if' will be executed if the character is ... I am not familiar with Perl, but I would assume that it would behave in a similar way to almost any other programming language. ...
    (comp.lang.php)
  • Re: How do I replace a character with another?
    ... cells with formulas, and it doesn't work. ... "Bill Kuunders" wrote: ... > For more than one character you may have to use the macro again. ... What if I wanted to substitute multiple ...
    (microsoft.public.excel.misc)
  • Re: Valkyrie: NBC
    ... Since when have critics panned movies based on the bad "character" of the ... Bill L. ... movies to see a Tom Cruise film before. ...
    (rec.music.artists.springsteen)