BitSensei

programmer knowledge

  • Increase font size
  • Default font size
  • Decrease font size
PERL

Initializing a variable with an array reference

E-mail Print PDF

To initialize a variable with an array reference in PERL:

 
 
my $arrayref = [];
 
 

Remember that $arrayref is a scalar variable that acts like a pointer to an array. You can also initialize it with values like so:

 
 
my $arrayref = [ "hello", "world" ];
 
foreach my $word (@$arrayref) {
    print "$word\n";
}
 
 

Last Updated on Thursday, 28 May 2009 14:45