Hello All ,

I have a probelme with mycode . I have written a code which accpets the character from a keyboard and checks , whether the input character is same as in the array on a character by character basis.

But , while it takes the input .its getting executed twice . Even I tried with STDIN , its hanging up after input so , no further processing .

Please help me to get rid of this .

My code is

<code> #! /usr/bin/perl open (FILE, "c:\\Users\\yashu\\Desktop\\SNLP\\EX4\\test.txt" ) || die +$!; undef($/); $mytext = <FILE>; $mytext = lc($mytext); $mytext =~ s/[^a-z|]/ /g; @wordarray = split(//,$mytext); print "@wordarray \n "; $len =@wordarray ; print "\n the lenght of the array is : $len "; $i=0; $j=0; $iter=0; while ($i<=$len-1) { print " \n Value of i is : $i "; print " \n Value of j is : $j "; print " \n Value of character in array is : $wordarray[$i] "; print " \n Enter the character : "; $char = getc(); #$char = substr($character,1); print " input is $char "; chomp($char); print " \n inputted character is : $char "; if ( $char eq $wordarray[$j]) { print "Correct !!"; $iter++; $count[$i]=$iter; $j++; $i++; $iter=0; } else { print "\n Wrong please try again "; $iter++; print "\n Number of attempts : $iter "; } }

In reply to getc working twice . by yashavanth

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.