Well, I would think you could rewrite it like:
for( $poll ) {
  $filehash{$title}{"Newspaper"}++, last if( /newspaper/ ); 
  $filehash{$title}{"Word of Mouth"}++, last if( /wordofmouth/ );
    $filehash{$title}{"Friend"}++, last if( /friend/ );
   die "Should not get here!";
  }
  write_results( $poll_file, $filehash );
----- Original Message ----- 
From: "Daniel Falkenberg" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 14, 2002 8:51 PM
Subject: Writing this chuck of code a little smaller...


> 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
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to