Re: Convert potion of string to Octal
- From: "ced@xxxxxxxxxxxxxxxxxxxxx" <ced@xxxxxxxxxxxxxxxxxxxxx>
- Date: 3 Jan 2006 15:07:15 -0800
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
.
- Follow-Ups:
- Re: Convert potion of string to Octal
- From: Bill H
- Re: Convert potion of string to Octal
- References:
- Convert potion of string to Octal
- From: Bill H
- Re: Convert potion of string to Octal
- From: John W. Krahn
- Re: Convert potion of string to Octal
- From: Bill H
- Re: Convert potion of string to Octal
- From: Paul Lalli
- Re: Convert potion of string to Octal
- From: Bill H
- Convert potion of string to Octal
- Prev by Date: FAQ 4.69 How can I use a reference as a hash key?
- Next by Date: Re: How to get image size in these conditions ?
- Previous by thread: Re: Convert potion of string to Octal
- Next by thread: Re: Convert potion of string to Octal
- Index(es):
Relevant Pages
|