* "Ing. Branislav Gerzo" <[EMAIL PROTECTED]> [2005-11-02T08:52:39]
> I have quite interesting work. Example:

I wish /I/ could find this sort of work interesting!  Or profitable.

> Now, I have to find all 2 words sentences with their sums in the list.
> For example for this list it could be (without reporting lines):
> "foo bar" - 5 times (lines: 3, 4, 5, 7, 8)
> "bar bar" - 2 times (lines: 4, 6)
> "bar foo" - 3 times (lines: 5, 6, 8)
> "foo foo" - 1 time (line: 7)
> "foob bar" - 1 time (line: 9)
> "foo bars" - 1 time (line: 10)

 my %occurances; # we'll put occurances here
 
 while (<>) {                # get each line of argument files (or sdin)
        chomp;                    # eliminate the newline
        my @words = split /\s+/;  # break into words on spaces
        next if @words != 2;      # we only care about two-word lines
        push @{$occurances{"@words"}}, $.; # add current line ($.) to list of
                                           # lines where we saw these words
 }

 for my $words (keys %occurances) {      # for each found paid
         my @lines = @{ $occurances{$words} }; # get the occurances
   print
                 "$words - seen ",   # we saw this paid...
                 scalar @lines,      # as many times as there are occurances
                 " times: (lines: ", join(", ", @lines), ")\n"; # and then list 
lines
 }

-- 
rjbs

Attachment: pgp8W7sbmGZJU.pgp
Description: PGP signature

Reply via email to