martes, 15 de noviembre de 2016

My first post on Perl



So yes...I started to learn Perl...why? 3 simple reasons...


  1. I love programming.
  2. For me...Perl belongs to the whole trinity of Scripting Languages along with Ruby and Python (Sorry PHP...you don't make the cut)
  3. Because...it's Perl! Come on!

So...I have been reading Beginning Perl...an awesome book by the way...



If you're using any flavor of Linux or Mac...you should have Perl installed already...if you're using Windows...well...you can always download it and install it -:)

So far...I love Perl...it's pretty amazing...and now I can see why people say that both Python and Ruby heavily borrow stuff from Perl...and sure...PHP too...

I don't have of course much experience...but as always...I start doing a simple and small program to get me into the right track...so here's my Fibonacci numbers app...

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

sub fib {
 my ($num,$a,$b) = @_;
 my $result = '';
 if ($a>0 && $num>1){
  $result = $result . ($a+$b) . " " . fib($num-1,$a+$b,$a)
 }elsif($a == 0){
  $result = $a . " " . $b . " " . ($a+$b) . " " . fib($num-1,$a+$b,$b)
 }
 return $result
}

print "Enter a number: ";
my $num = <>;

print(fib($num,0,1));

And here's the nice output...


By now...I already have my classic "LED Numbers" app ready...but that goes into another post -;)

Greetings,

Blag.
Development Culture.