Tuesday, October 18, 2011

Perl - [ References /pointers variables ]


Anyone familiar with the C language (and other), you know whatpointers are and how programming can become proficient with its use. References are pointers to previously defined data types(whether it's scalars, arrays or hashes). Through references it is possible to obtain the contents of a scalar variable, an array or ahash the same as using the original name.
------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my (%HoA,$valor,@nome);
#References scalar ($)
$valor = 10;
my $rvalor = \$valor;
print "$$rvalor\n";

#References array (@)
@nome = ('andre','ayres');
my $rnome = \@nome;
print "$$rnome[0]\n";



#References hash (%)

@{$HoA{'1'}} = (1..10);
print join("\t",@{$HoA{1}}) , "\n";

my $rHoA = \%HoA;
print join ("\t",@{$rHoA->{1}});

result 

$perl tmp.pl 

10
andre
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10

0 comentários:

Post a Comment