Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Smiley (emoticon) encoding scheme

by polettix (Vicar)
on Jul 01, 2005 at 01:59 UTC ( [id://471528]=sourcecode: print w/replies, xml ) Need Help??
Category: Fun Stuff
Author/Contact Info Flavio Poletti
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
Description: A simple encoding scheme using four smileys. Example:
user@host> perl -e 'do "smiley.pl"; print encode("ciao")' :D :( :) :/ :/ :) :) :/ :/ :( :) :/ :D :D :) :/ user@host> user@host> perl -e 'do "smiley.pl"; print decode(":D :( :) :/ :/ :) :) + :/ :/ :( :) :/ :D :D :) :/"), $/' ciao
#!/usr/bin/perl
# Copyright (C) 2005 by Flavio Poletti
# (perl -ple'$_=reverse' <<<ti.xittelop@oivalf)
# NO WARRANTY AT ALL
# Same license as Perl, as of version 5.8.0 or following
use warnings;
use strict;
 
sub encode {
        local $_ = unpack "b*", pop;
        my @smileys = qw| :( :/ :) :D |;
        s/(..)/$smileys[ord(pack"b*",$1)].' '/ge;
        s/(.{1,63})/$1\n/g;
        $_;
}
sub decode {
        local $_ = pop;
        my %smileys = ( D => '11', '(' => '00', ')' => '01', '/' => '1
+0');
        s/:(.)\s*/$smileys{$1}/ge;
        pack "b*", $_;
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://471528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-19 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found