shahriyar85 has asked for the wisdom of the Perl Monks concerning the following question:

Good day...
I have this small cgi form the problem is that the variables won't pass to split.. but when I give a direct value to the variables everything is ok... here is the code *note the unreadable characters are Arabic please ignore them:
#!/usr/bin/perl use utf8; use Switch; use CGI; $cgi = new CGI; print $cgi->header(-charset=>'UTF-8'), $cgi->start_html ( -title=>'Mahsoob Script' ), $cgi->h1('Mahsoob script'), $cgi->start_form ( -method=>'post', -action=>'' ), "Textbox: ", $cgi->textfield(-name=>'name',-size=>20), $cgi->br, "\n", "Textbox: ", $cgi->textfield(-name=>'mom',-size=>20), $cgi->br, "\n", "Textbox: ", $cgi->textarea(-name=>'tarekh',-coloumns=>20,-rows=>5), $cgi->br, "\n" +, $cgi->submit(-value=>'submit'), $cgi->br, "\n", $cgi->end_form; print "<br>"; $name = $cgi->param('name'); $mom = $cgi->param('mom'); $tarekh = $cgi->param('tarekh'); %freq = ( --arabic characters and their values ); %freq2 = ( --arabic characters and their values ); $namesum = 0; for (split //, $name) { $namesum += $freq{$_}; } $momsum=0; for (split //, $mom) { $momsum += $freq{$_}; } $sum=$namesum+$momsum; print "Sum: $sum\n"; $modulus =$sum%12; switch ( $modulus ) { --12 different cases , simple print statement } print $modulus; $cgi->end_html;

Replies are listed 'Best First'.
Re: CGI won't pass to split
by Corion (Patriarch) on Jan 19, 2009 at 14:08 UTC

    You're using the Switch.pm module. Remove it. It introduces errors into your programs that are hard to track down. It provides little gain for lots and lots of pain. Also, I think your syntax for the case statements is wrong, but again, just use if ... elsif ... else instead. It makes life easier for everybody.

      Thank you I tried and removed the switch from the code but the problem still ... the result is always 0.. unless I provide a direct value for the variable..

        Do you want to show us the code? Otherwise, I guess that the problem is on line 42.

Re: CGI won't pass to split
by jeffa (Bishop) on Jan 19, 2009 at 14:38 UTC

    Clean your room! Your code is much too chaotic for you to expect us to figure out on our own. Rather than you assuming you know what the problem is and only asking for us a small solution to get your chaotic code to work, maybe you should instead explain what you are trying to accomplish.

    If you truly do believe that the problem is where you think it is, then raise an exception when the values for $mon and $name are undefined or not what you expect them to be. And don't forget next time to Clean your room. :) Don't just give us the whole script, rewrite just the portion you are having trouble with -- by doing so you might just solve the problem yourself.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      I updated the code to be cleaner now... as for what i am trying to do is ... Get 2 arabic strings, split them, and give an integer upon the values of each characters defined in the hashes.
Re: CGI won't pass to split
by almut (Canon) on Jan 19, 2009 at 15:55 UTC

    I haven't tried it, but maybe you want

    use Encode; ... my $name = decode('UTF-8' => $cgi->param('name') );

    etc... in order to properly have the parameters decoded.  There's also a related CGI.pm option (pragma) "-utf8" ("This makes CGI.pm treat all parameters as UTF-8 strings."), but be sure to read the note in CGI.pm's manpage.

    The -charset=>'UTF-8' you already have will only have an effect on what's being sent to the browser on output, and the use utf8; only tells Perl to interpret the script source as UTF-8.

      Thank you sir, that solved the problem.. regards