segunda-feira, 19 de fevereiro de 2007

Perl and Unicode


#!/usr/bin/env perl
#
use strict;
use charnames ':full';
use utf8;

# First, let's print the source code.
open THIS, $0;
print $_ while (<THIS>);

# Get the vector elements sum. We use the Sigma greek letter.
sub Σ
{
my ($accum) = shift;

foreach(@_)
{
$accum += $_;
}
return $accum;
}

# My Day is done!
# But Gauss would do it better!
# We can see that perl allows any
# Alphabet caracter to be used, but any symbol
# is reserverd. This is the case of integral symbols
# ∫, ∬, ∭, ∮, ∯, ∰, ∳, ∲. and even the Summantion sign ∑
# Note that this is not the greek sigma letter. Perl is smart, hum?

my @Ϯ = 1 .. 100;
my $ΔU = Σ @Ϯ; # Σ is not ∑. (Sigma and summantion sign).

print "The Summation from one to a handred is $ΔU.\n";

# Energy Funcion Ψ.
# It goes from ± a radius around
# the center.
sub Ψ
{
my ($α,$β,$γ) = @_[0..2];
return $α**2 + $β**2 + $γ**2;
}



# My runic letter Gar
my $ᚸ = Ψ(2.3, 234.0, 23.4);

# Listing day in Japanese, from Sunday to Saturday
my @Ա = qw/㈰ ㈪ ㈫ ㈬ ㈭ ㈮ ㈯/;

# A dictionary.
my %Ծ =
(
"㈰" => ["Sun", "Sunday"],
"㈪" => ["Moon", "Monday"],
"㈫ " => ["Fire", "Tuesday"],
"㈬" => ["Water", "Wednesday"],
"㈭" => ["Wood", "Thursday"],
"㈮" => ["Metal", "Friday"],
"㈯" => ["Earth", "Saturday"],
);


# Now, lets print the sign for Astrological sign.

my $signs = join ", ", map { chr(ord("♈") + $_ - 1) } 1..12;

print "This is a list with the signs $signs.\n";

foreach my $Ʃ (@Ա)
{
print "$Ʃ is the Japanese symbol for $Ծ{$Ʃ}->[0] element, also $Ծ{$Ʃ}->[1] week\'s day.\n";
}




Quem sou eu

Minha foto
I used to work with embedded software and digital design. Now my career is about to turn in a complete different direction ...