in reply to break up the problem
in thread Searching Files

cebrown, I tried doing this...... I already created a hash dataname with the names......
foreach $Name (sort keys %dataname) { for (APRIL, MAY, JUNE) { if ($count{$Name}) { $count{$Name}++; } } printf OUTFILE "%-50s %d\n", $Name, $count{$Interface_Name};
but it just seems to be adding 1 count after each loop...any suggestions?

Replies are listed 'Best First'.
Try reading your code in English
by dragonchild (Archbishop) on Jul 24, 2002 at 22:02 UTC
    Are you sure your code is doing what you think it's doing? When I read it, it's saying
    1. For every name in this list, do the following:
      1. If I have a non-zero number in the location $count{$Name}, then I need to add 1 to the location specified by $count{Name}
    2. Print stuff out to somewhere.

    That doesn't seem like that's what you want to do. In fact, it's doing exactly what you're complaining it's doing. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: Re: break up the problem
by cebrown (Pilgrim) on Jul 24, 2002 at 21:53 UTC
    Well, "APRIL, MAY, JUNE" is just a list of three strings. Perl is iterating across each element in that list and doing the stuff inside the for loop exactly three times, once for each string.

    Elsewhere in the program I assume you did something like open APRIL, "<200204";. If that's the case, you need to use the special angle bracket operator to iterate through each record in a file, like while(<APRIL>) {do stuff}. Note also that while you are looping through each file you still need to perform the split on each record in order to find the name that's on a given record.

      Well, "APRIL, MAY, JUNE" is just a list of three strings.

      Hopefully not. Or to be more precise: Hopefully they're constants (which can be strings, but who knows?).

      Cheers,
      -Anomo