geostorm.org


UTC 09:31:50
Thursday
11/21/2024



November 2024
SuMoTuWeThFrSa 
     12 
3456789 
10111213141516 
17181920212223 
24252627282930 
        
Calendar Tool

welcome

Scalars, Arrays, Hashes, and multi-dimensional arrays and hashes



Simple scalar:
$s = "hello";

Simple array:
@a = ("color", "name", "hair");

Simple hash:
%h = ( "color", "red", "name", "bob", "hair", "black");
Same as:
%h = (
"color" => "red",
"name" => "bob",
"hair" => "black"
);


Hash of array:
$properties{"colors"} = [ "blue", "red", "green", "brown", "orange", "yellow" ];


$properties{"person"} = {
"vehicle" => ["sedan", "coupe", "SUV", "truck", "wagon"],
"name" => ["nancy", "joe", "bob", "lisa", "lee"],
"hair" => ["brown", "black", "gold", "red", "none"],
"home" => ["colonial", "multi-family", "apartment", "condo", "co-op", "trailer", "tent"],
};

same as:
$properties{"person"}{"vehicle"}[0] = "sedan";
$properties{"person"}{"vehicle"}[0] = "coupe";
$properties{"person"}{"vehicle"}[0] = "SUV";
etc...
This method, a complex multi-demensional array can have individual values added or changed just like a simple scalar.

Mixed multi dimensional arrays and hashes:
Hash:
%x = (
"a", "1",
"b", "2",
"c", "3",
"d", ['z', 'x', 'y']
);


$z = $x{d};
@z = @$z;
print "$_, " for @z;



After receiving a 3D array from a function

my @x = myFunction();
my $a = shift @x;
my @a = @$a; # final product


send an array:
myFunction ( \@myArr, \@myList);

Add to a 3D array:
push @x, \@array;



Push elements into 3D array in a loop:

@array3D=();
for $count (0..3){
   for $insideItem (1..10){
      push @{ $array3D[ $count ] }, $insideItem;
   }
}

# print it out:
for my $x (@days3d){
    for my $inner (@$x){
        print "($inner)";
    }
    print "next group\n";
}



---------------
removing lines in hash

%Hash = ( your keys and values here);
@delList = ( list of keys to delete goes here );
delete @Hash{ @delList }; # @ instead of % to delete multiple lines in hash