develooper Front page | perl.fwp | Postings from November 2001

Re: isprint Golf Challenge

Thread Previous | Thread Next
From:
Keith C. Ivey
Date:
November 17, 2001 06:37
Subject:
Re: isprint Golf Challenge
Message ID:
3BF62FD2.25327.2C916A8@localhost
I wrote:

> If you're interested only in golf, and don't care about those
> issues, you can eliminate several bytes easily:
> 
>     $str=~s/[^ -~]/sprintf'\%03o',ord$&/ge;

If hexadecimal escape codes are acceptable in place of octal,
you can save another 3 bytes:

      $str=~s/[^ -~]/'\x'.unpack H2,$&/ge;

Save 4 more bytes by using \c escapes, but that doesn't handle 
anything above 127, and I doubt PostgreSQL would like it 
anyway:

      $str=~s/[^ -~]/'\c'.($&^'@')/ge;


-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About