Perl Array Data Structure
Jump to navigation
Jump to search
A Perl Array Data Structure is a perl data structure that behaves like an array data structure.
- Context:
- It can (typically) be based on a Perl Array Data Type.
- It can support a Perl Array Operation, such as a Perl Join Subroutine.
- It can be an input to an Array-input Perl Subroutine,
- It can be:
- a Perl Tuple for a tuple data structure.
- a Perl Vector for a vector data structure.
- a Perl Array of Arrays, such as a Perl Matrix.
- a Perl Array of Hashes.
- Example(s):
@Tuple = ("One", "Two", "Three")
- Counter-Example(s):
- a Perl Associative Array.
- a Python Array Data Structure, such as a pandas.DataFrame.
- See: Perl Coding Example, Perl Built-In Datatype.
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