In my quest to improve
QuizTaker.pl, I am trying to modify it, so that it can
accept questions that are a combination of multiple choice and true/false. What I
need to accomplish this (I think), is to be able to read the length of array that is
the value of a key within a hash. I have a small test function below, but it doesn't
quite work. It merely gives the memory address of the array. Any suggestions?
#!/usr/bin/perl -w
use strict;
my @value1=(1,2,3,4);
my @value2=(5,6);
my @value3=(7,8,9,0);
my %Hash = (Key1=>\@value1,Key2=>\@value2,Key3=>\@value3);
my @hasharraylengths=();
my $length = 0;
foreach my $key (keys %Hash){
$length = $Hash{$key};
push @hasharraylengths, $length;
}
my $l = @hasharraylengths;
for(my $x=0;$x<$l;$x++){
print"Length of Value: $hasharraylengths[$x]\n";
}
TStanley
In the end, there can be only one!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.