develooper Front page | perl.beginners | Postings from March 2002

Writing this chuck of code a little smaller...

Thread Next
From:
Daniel Falkenberg
Date:
March 14, 2002 17:51
Subject:
Writing this chuck of code a little smaller...
Message ID:
3ACA70B144BD6D45B994CAC2CA4B9F9801650D@opal.vintek.local
D'day all,

I have the following chunk of code that I was wondering If I can write a
little smaller.  I was thinking a while loop.  Could some one give me a
little advice on this one :)...

results_read();
    if ($poll =~ /newspaper/) {
      print "Thank you for picking news paper!";
      $nonewspaper = $filehash{$title}{"Newspaper"};
      $new_newspaper_total = $nonewspaper + 1;
      $filehash{$title}{'Newspaper'} = $new_newspaper_total;
      write_results($poll_file, $filehash);
    } elsif ($poll =~ /wordofmouth/) {
      $no_wordofmouth = $filehash{$title}{'Word of mouth'};
      $new_no_wordofmouth = $no_wordofmouth + 1;
      $filehash{$title}{'Word of mouth'} = $new_no_wordofmouth;
      write_results($poll_file, $filehash);
    } elsif ($poll =~ /friend/) {
      $no_friend = $filehash{$title}{'Friend'};
      $new_no_friend = $no_friend + 1;
      $filehash{$title}{'Friend'} = $new_no_friend;
      write_results($poll_file, $filehash);
    } else {
      # Theoretically there shold never be a non match as we are using
radio
      # buttons!
      print "No Match!";
    }
    results_read();

It's pretty straight foward... Basically if $poll matches what I have
told it to match then we it goes and writes some results to a file.  I
have a tingling feeling that I would be better off using a whilt loop.
I just don't know where to start.

Kind regards,

Dan

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About