martes, 15 de noviembre de 2016

LED is my new Hello World - Perl Time

As promised...here's my LED Numbers a la Perl...and as always...please keep in mind that I'm Perl newbie...I know that there are more efficient, short and concise way of doing this app...but...how good is an introductory code that uses some obscure and arcane code? I don't want to scare people away from Perl...I want people to say "Hey...that doesn't look hard...I want to learn Perl"...

So...here it is...

LedNumbers.pl
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

my %leds = (
 0 => ' _  ,| | ,|_| ',
 1 => '  ,| ,| ',
 2 => ' _  , _| ,|_  ',
 3 => '_  ,_| ,_| ',
 4 => '    ,|_| ,  | ',
 5 => ' _  ,|_  , _| ',
 6 => ' _  ,|_  ,|_| ',
 7 => '_   , |  , |  ',
 8 => ' _  ,|_| ,|_| ',
 9 => ' _  ,|_| , _| '
);

print "Enter a number: ";
my $num = <>;
my @numbers = ( $num =~ /\d/g );

for my $i (0 .. 2){
 for my $j (0 .. scalar(@numbers) - 1){
  my @line = split /\,/,$leds{$numbers[$j]};
  print $line[$i];
 }
 print "\n";
}

And here's the output...


And just so you know...this is my 24th version of this code...yep...I have written my LED Numbers app in 24 languages so far -;) What's going to be my end point? Who knows...programming is the limit -;)

Greetings,

Blag.
Development Culture.

No hay comentarios: