Perl Array Data Structure

From GM-RKB
(Redirected from Perl array)
Jump to navigation Jump to search

A Perl Array Data Structure is a perl data structure that behaves like an array data structure.



References

2012

  • (Melli, 2012-08-31) ⇒ Gabor Melli. (2011). “Perl Array Examples."
Populate manually
   my @Tuple1a  = ("One", "Two", "Three");
   my @Tuple1b  = qw(One Two Three);
   my @Tuple2a  = (@Tuple1a, "Four"); # append
   push(@myNames, "Five", "Six"); 
   my @Tuple2b  = (@Tuple1b, @Tuple2a, "one more"); # append
   my @Vector1  = (3, 1, 4);
   my @Vector2  = (2, 5, 11);
   my @Vector3  = (1, 7, 4);
   my @Matrix1a = ([3, 1, 4], [2, 5, 11], [1, 7, 4], );
   my @Matrix1b = (\@Vector1, \@Vector2, \@Vector3 );

Populate from a file.
   my @Array ;
   while (<>) {
      my @tmp = split (/\t/);  # Split elements into an array.
      push @Array, @tmp ;
   }
Loops
   for $i (@array) {
     print $i ;
   }
Transforming into a string
  $string = join(", ",@Array );
Emptying
  @Array = (); # completely empty @ARRAY
  $#Array = -1 ; # reset the index
  undef @Array ; # forget @Array ever existed