Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
Perl 101 - Part IV.
  • rx-
    Posts: 169
    Perl 101 - Part IV.

    Hash variables and what are they good for


    #!/usr/bin/perl -w
    use strict;

    my @hash;
    my %hash = (
    \"Xinapse\", \"Admin\",
    \"Chroniccomand\", \"Mod\",
    \"GameOver\", \"Gamer and Mod\", # This is how we declare hash array
    \"rx-\", \"The author\",
    \"LEET\", 1337
    );

    my $hash1 = $hash[1]; # Value is _Admin_
    my @hash2 = %hash; # Regular array with 10 items (ie. all info)
    my %hash3 = @hash2; # Now we made a hash array from list(regular) array, its same as %hash

    foreach my $hash4 (keys %hash) {
    print $hash4.\"\n\"; # Will print keys(Xinapse,Chroniccomand,GameOver) etc.
    }

    foreach my $hash5 (values %hash) {
    print $hash5.\"\n\"; # Will print values (Admin,Mod, Gamer and Mod) etc.
    }

    my ($name,$position); # You define more variables REMEMBER IT!

    while(($name, $position) = each(%hash)) {
    print $name.\" - \".$position.\"\n\"; # Will print key and value (fe. \"Xinapse - Admin\")
    }


    This should give you a good overview of what perl hash, also called associative arrays are good for, if you cant think about using it, imagine this:
    You have an array full of IPs, vulnerable and not vulnerable, and you want to associate with them their state, like service version, or if they are vulnerable or not, and thats when hash arrays come handy!

    Stay tuned, more to come, rx enjoys the ride!

    If you found this tut interesing, please click this LINK
  • Xin
    Posts: 3,251
    Another great tut on perl, keep it up bro
    Xin
  • h4ckingURLife
    Posts: 125
    Nice work mate. Lovely tut on Perl.