Perl Useful Commands
How to delete an array
@array1 = ();
Open a file for reading
my $FH;
open $FH, '<', "file.txt" or die "Cannot open file\n";
Close a file
close $FH;
Split command
@array1 = split 'pattern', @array2;
Sorting the contents of array
@new_array = sort @original_array;
Adding data to array
push @array, $element;
Pop the array
$elememt = pop @array;
for statement for array processing
for $element (@array) {

}
foreach
foreach $x (keys (%ENV)) {
	      print $x
}
Perl command line substring

To access a variable defined in shell, the variable has to be first exported and use Perl's %ENV hash.

str='The is a line'
export str
		  
perl -e '{print $ENV{"str"}}'

perl -e '{print length $ENV{"str"}}'

perl -e '{print substr $ENV{"str"}, 1, length $ENV{"str"}}'
	
perl -e '{foreach $key (keys (%ENV)) {print $key . " ---> " . $ENV{$key} . "\n"}}'    
each Statement

each returns a 2 element list, each being the key and value of the hash

while (($key, $val) = each %ENV) {

    print $key . ' - ' . $val;
}
Perl's special symbols
$|++ set command buffering
Comments