in reply to Script to reduce tokens to minimal unique characters
On the other hand, maybe you wanted a hash with all the valid unique prefixes of @tokens, like this:
#!/usr/bin/perl # http://perlmonks.org/?node_id=1130246 use strict; use warnings; my @tokens = qw/report_time report_day reset read/; my %valid; # generate hash with valid unique matches /^(.+)(??{$valid{$1}++})^/ for @tokens; delete @valid{grep $valid{$_} > 1, keys %valid}; /^(\w+)/ and $valid{$1} and print "$1\n" while <DATA>; __DATA__ report_t 14:09:33 PDT report_d Fri Jun 12 2015 report (should not show up) res Resetting the time report_time 00:00:00 rea foo.bar Info: reading file foo.bar
|
|---|