in reply to create a perl script for pattern matching

Isn't there a "FROM" part missing? Anyway, this is a typical hash-count problem.
use strict; use warnings; my %data; while (<DATA>) { chomp; next unless $_; $data{$_}++; } for ( keys %data ) { print "$data{$_} : $_\n"; }


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: create a perl script for pattern matching
by anonymized user 468275 (Curate) on Jul 01, 2005 at 13:06 UTC
    The catch I can see here is that SQL can be expressed on multiple lines and might have irrelevant variations (like one extra space after the SELECT) causing a statement to be entered under a separate count. Or what about 'WHERE A.A=C.A' being logically identical to 'WHERE C.A=A.A' - traversing output from a parser seems the only really reliable approach.

    But that aside, once the parsing problem is resolved, the hash count is indeed the best way to finish off.

    One world, one people