#!/usr/bin/perl -w use strict; use CGI ':standard'; my $data="/path/data_add.txt"; my $checkthree = param('check'); my $num = param('num'); my $action = param('action'); my @line1 = (); my @line_no = (); my ($one,$two,$three,$four,$five); print header(), start_html; open (FILE,"$data") || die "whoops: $!"; while (my $line =) { ($one,$two,$three,$four,$five) = split "\t",$line; if (($action eq 'Put') && ($three eq $checkthree)) { $five = $five + $num; print "we have $five on line $.
"; @line1 = ($one,$two,$three,$four,$five); push (my @line_no, $.); print "Did this work @line_no
"; last; } elsif (($action eq 'Take') && ($three eq $checkthree)) { $five = $five - $num; @line1 = ($one,$two,$three,$four,$five); push (@line_no, $.); last; } } close FILE; if ($five < 0) { print "message: can't do this"; } else { my $line1 = join "\t", @line1; print "taking it out of the loop we have @line_no
"; my $line_no = join " ", @line_no; print "we have $five on line $line_no
"; open (FILE,"$data") || die "whoops 1: $!"; my @all=; close (FILE); $all[$line_no-1] = $line1; open (FILE2,">$data.tmp") || die "whoops 2: $!"; foreach my $line (@all){ $line=~s/\n//g; print FILE2 "$line\n";} close(FILE2); rename("$data.tmp", "$data") || die "whoops 3: $!"; print "the field now contains: $five"; } print end_html();