Friday, April 13, 2012

Perl - " How to truncate decimal places "

#!/usr/bin/perl
use strict;
use warnings;

my $Num = 1.3333;

printf ("% .2f",$Num);

Result :
$perl blog.pl
1.33

Perl - Ref -> Array of Array

#!/usr/bin/perl
use strict;
use warnings;

my @web = ('Command Line','Blog');
my @www = ('http://andre-als.blogspot.com.br/2011/10/perl-table-reference-o.html','=)');
my @data = (\@web,\@www);

foreach my $array (@data){

    #print join ("|", @{$array});

    for(my $i = 0; $i <= $#{$array}; $i++ ){
        print "@{$array}[$i]\n";
    }
}


Result:

$ ./tmp.pl
Command Line
Blog
http://andre-als.blogspot.com.br/2011/10/perl-table-reference-o.html
=)