I am trying to organize a get together of people from my singing group using a CGI script. The optimum solution is to find the day where most people can attend from a choice of the days given.

At the beginning of the script I read in the relevant data from a file and then add the data collected. This is stored in a hash that contains a list of people that can't attend(value) on any day (key) (in the interests of politeness I want to store thier names so that if there isn't a day where everyone can attend we can at least let people know who can't come)

I then want to create a hash whose key is the day and whose value is the number of people who can't attend. My solution is below but my question is can I do this by using scalar on the hash value directly without creating the unecessary array?

#! /usr/bin/perl -w # %hash1=("key1"=>"value1","key2"=>"value2"); %cant_make_day =( "Mon"=>"Jim", "Tues"=>"Jim, Paul", "Weds"=>"Jim, Paul, Annie" # real people! ); while (($elim_key,$elim_value) = each %cant_make_day) { # is this array necessary? @array= split /,/, $cant_make_day{$elim_key}; $length=@array; # sets value to length of array stored in hash $which_day{$elim_key}=scalar @array; print "The number of people on $elim_key = $which_day{$elim_key}\n"; }

In reply to Finding the length of an aray in a hash by tallus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.