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

Hi Monks
Hope you can help me. I have the following code which takes in results and posts them to a storage file for later retreval.
# update values with this weeks results and scores for (my $j = 0; $j <= $#teams; $j++) { print "\nDo You have results for $teams[$j] (y\\n)?\n"; $answer=<STDIN>; chomp($answer); if ($answer =~ /[Yy](es)*/) { $team_number = $j*5; $Values[$team_number]=$teams[$j]; print "$j\t\t$Values[$team_number]\n"; print "\nHome Result ((W D or L) _ if its an away game):\n +"; $home_result=<STDIN>; chomp($home_result); $home_result=~s/\s+$//g; $Values[$team_number+1]=~s/($Values[$team_number+1 +])/$1$home_result/g; exit 1; } # update storage file open(SNMPFILE,"+< store.txt"); for ($ae = 0; $ae <= $#Values; $ae++) { print SNMPFILE "$Values[$ae] "; } close(SNMPFILE);
The problem is when I am typing in a result and I get it wrong and backspace over it and enter the correct value the file gets updated with the old value as well as the new value
This is what appeared in the file when I typed in W then backspaced and printed D : WD
Is there a way to rectify this?

Replies are listed 'Best First'.
Re: overwritten values showing in storage file
by jfroebe (Parson) on Nov 10, 2004 at 17:49 UTC

    Make your life a bit easier, take a look at Term::ReadLine. It will handle the backspaces and the like

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

      Thanks
      I took your advise and used Term::ReadLine. Its nice to know that there is a module for almost anything in perl. Pity there is no module to edit a file on a remote machine though. That would be nice
      Thanks again.

Re: overwritten values showing in storage file
by ikegami (Patriarch) on Nov 10, 2004 at 16:14 UTC

    That's odd.

    $in = <STDIN>; print(length($in), $/);

    Prints 2 for dddddddddd^H^H^H^H^H^H^H^H^H^Hd in both Windows and FreeBSD. (Newline included because chomp not used.) What do you use?

      cygwin.

        You could fix it manually, I suppose
        while ($input =~ s/.?\x08//) {}
        The following is NOT the same:
        $input =~ s/.?\x08//g;