in reply to Creating (and using) a custom encoding.
I like Anonymous Monk's suggestion, as it facilitates "compiled" encodings. I'd still like to figure out the Encode::Encoding method though. Afterward I can probably post a tutorial on both methods.
Here's a self-contained snippet that should be a framework from which to work on getting the Encode::Encoding method going. Unfortunately, it doesn't work (ie, the rot13 encoding doesn't take place) because I'm still unclear on how Encode's define_encoding() fits into the mix. If anyone can fill in the blank, or possibly point to the documentation that I seem to have missed, I would certainly appreciate it.
package Encode::ROT13; use strict; use warnings; use parent qw( Encode::Encoding ); __PACKAGE__->Define( 'rot13' ); sub encode($$;$){ my( $obj, $str, $chk ) = @_; $str =~ tr/A-Za-z/N-ZA-Mn-za-m/; $_[1] = '' if $chk; # $_[1] is aliased through the call. Inplace edi +t. return $str; } no warnings 'once'; *Encode::ROT13::decode = \&encode; # Because rot13( rot13() ) is a rou +nd-trip. 1; package main; use strict; use warnings; use Encode 'define_encoding'; use File::Slurp; # define_encoding( $object, 'rot13' ); # Um....? my @words = read_file( \*DATA, chomp => 1, binmode => ':rot13' ); print "$_\n" for @words; __DATA__ Apple cat dog strawberry watermelon
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating (and using) a custom encoding.
by Khen1950fx (Canon) on May 30, 2013 at 20:29 UTC | |
by davido (Cardinal) on May 30, 2013 at 20:56 UTC | |
by Khen1950fx (Canon) on May 30, 2013 at 23:37 UTC | |
|
Re^2: Creating (and using) a custom encoding. (fudge :encoding(rot13))
by Anonymous Monk on May 30, 2013 at 23:41 UTC |