Tag Archive


3D 3dprinting android ant BigData bitcoin Browsers C/C++ cryptocurrency CSS dd ddrescue dogecoin DOS editors find Games Git hadoop html html5 Java Linux litecoin node perl Postgres Programming Python scripting Shell SQL Swing TOTK Utilities utilization vi Video Web Web Design Wifi Windows Wordpress XML Zelda

Perl: Arrays

I use perl arrays in some of my programs, and just started to look at the regular things that I do with these arrays and thought it would be useful to keep a list of frequently used items.

Create a variable specified as an array.

my @vararray

Add an item to the beginning of an array

unshift (@vararray, "File2");

Add an item to the end of an array

push (@vararray, "File1");

Remove an item from the beginning of an array

my $var = shift(@array);

Remove an item from the end of an array

pop(@array)

Clear an array

@vararray = ();

Address an item in an array

print $vararray[0] ; 

Get the size of an array

my $arraysize = @array;

Remove an item based on the index

delete @vararray[1];

Iterate over an array

foreach my $var (@vararay)
{
  print "$var n";
}
 
# or 
my $size = @vararray;
my $i;
for ($i = 0 ; $i < @size; $i++)
{
  print "$vararray[$i]n";
}