#!usr/perl/bin use strict; use warnings; use Data::Dumper; my $file0 = "foo.txt"; my $file1 = "bar.txt"; my $file2 = "blivitz.txt"; my @array1 = ($file0, $file1, $file2); print "Initial array:\n"; my $elementindex = 0; for my $file(@array1) { print "\$elementindex $elementindex is $file\n"; $elementindex++; } print "\n"; # Now adding an interior element to the array, in this case, arbitrarily inserting "new element" # after "foo.txt" and before "bar.txt" #(to add to beginning or end, see push and unshift) my @temp_array = @array1; # copy all elements to new array @temp_array = ($array1[0], "new element", $array1[1], $array1[2]); @array1 = @temp_array; # copy revisions back to @array1 $elementindex = 0; for my $file(@array1) { print "After revisions, \$elementindex $elementindex is $file\n"; $elementindex++; } print "\n"; # This REPLACES the latest content of $array1[1], "new element", with $addelement.txt # BUT note it's NOT "add"(ing) an element "anywhere" my $addelement = "addelement.txt"; $array1[1] = $addelement; # $elementindex = 0; for my $file(@array1) { print "now \$elementindex $elementindex is $file\n"; $elementindex++; }