Florida State University, Tallahassee, FL, USA, Dr. Whalley, COP4342 Unix Tools.
This program takes much of my previous assignment but adds the functionality of printing the concatenated line numbers found within the input.
Sample input from <> operator:
Hello World
This is hello
a sample program
this program.
The output from above should be:
hello: 2 times, lines 1, 2
world: 1 times, lines 1
this: 2 times, lines 2, 4
sample: 1 times, lines 3
program: 2 times, lines 3, 4
is: 1 times, lines: 2
Due to this being a current assignment I cannot submit all of my code for obvious reasons. I have the hash count for the instances correct. I'm having issues with finding and printing the lines (concatenated together, etc).
foreach $tempL (@line)
{
@cleanWords = split(/\s+/, $tempL);
for ($i=0; $i <= $#cleanWords; $i++)
{
if ( exists($occurCount{$cleanWords[$i]}) )
{
$occurCount{$cleanWords[$i]}++;
}
else
{
$occurCount{$cleanWords[$i]} = 1;
}
if ( length($cleanWords[$i]) > $currLongest )
{
$currLongest = length($cleanWords[$i]);
}
foreach $tempW (@line)
{
$newlineCount++;
if ( index($tempW, $cleanWords[$i])>0 )
{
$concLNums = $concLNums . "$newlineCount, ";
}
}
}
push @lineNums, $concLNums;
$concLNums = "";
$concLNums = 0;
}
my $counterUp = 0;
my $wordprint;
foreach $wordprint ( sort( keys(%occurCount) ) )
{
printf ("%${currLongest}s: %4d times, lines: %0s\n", $wordprint, $occurCount{$wordprint}, $lineNums[$counterUp]);
$counterUp++;
}
Any hints greatly appreciated. I know it's not difficult but I'm not focusing enough because I've spent hours changing it.