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

Writing this chuck of code a little smaller...

Thread Next
Daniel Falkenberg
March 14, 2002 17:51
Writing this chuck of code a little smaller...
Message ID:
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 :)...

    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
      # buttons!
      print "No Match!";

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,


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About