in reply to Re^3: Optional Arguments..?
in thread Optional Arguments..?

Thanks for the reply again. My lecturer doesn't really helps us with assignments, we are expected to complete it without his help. How do I print the hashes of arrays that I encoded, with or without the specified search string (site name)? I don't know how to tell the computer what I want to convey, I need a little help here :(

Replies are listed 'Best First'.
Re^5: Optional Arguments..?
by davido (Cardinal) on Jun 03, 2012 at 08:53 UTC

    Here's how you go about printing hashes of arrays. This should be general enough that you can adapt it to your situation once you work through the syntax and other errors in your code that are dumped to your screen when you type perl -c scriptname.

    Let's say you have a Hash of Arrays like this:

    my %HOA = ( this => [ 'A', 'B', 'C' ], that => [ 'D', 'E', 'F' ], other => [ 'G', 'H', 'I' ], );

    You could print a given element like this:

    print $hoa{this}[2], "\n"; # prints 'C'.

    ...or you could print each row like this:

    foreach my $key ( keys %HOA ) { print "$key:\t"; print "$_\t" for @{$HOA{$key}}; print "\n"; } # Prints the following (don't rely on the order of hash keys). # this: A B C # that: D E F # other: G H I

    Helpful documentation: perlreftut, perlref, perllol, perldsc.


    Dave