source keyedListLib.tcl ################################################################ # proc readFileAsList {fileName}-- # read in a file and convert it to a list delimited by newlines # Arguments # fileName Name of the file to read # # Results # no side effects # proc readFileAsList {fileName} { set if [open $fileName r] set d [read $if] close $if return [split $d \n] } set lst [readFileAsList practice.txt] set inputByLocalIP {} set outputByLocalIP {} foreach line $lst { lassign $line time in out localIP arrow remoteIP service if {$in ne ""} { # Retrieve the current total for this IP address set inTot [getValue $inputByLocalIP $localIP] # If the total is an empty string, this IP address has not # been added to the list. Set the inTot variable to 0 (no bytes # so far) and append this IP address and value to the list # of inputs if {$inTot eq ""} { set inTot 0 set inputByLocalIP [appendKeyedPair $inputByLocalIP $localIP $inTot] } set inTot [expr {$in + $inTot}] set inputByLocalIP [replaceValue $inputByLocalIP $localIP $inTot] set outTot [getValue $outputByLocalIP $localIP] if {$outTot eq ""} { set outTot 0 set outputByLocalIP [appendKeyedPair $outputByLocalIP $localIP $outTot] } set outTot [expr {$out + $outTot}] set outputByLocalIP [replaceValue $outputByLocalIP $localIP $outTot] } } foreach {ip in} $inputByLocalIP { set out [getValue $outputByLocalIP $ip] puts "$ip $in $out" }