#!/usr/bin/perl -w use strict; my $key = shift || die "You must pass key to match against\n"; my $re = shift || die "You must pass a regex to match against\n"; my $p = DevInput::Parser->new(); # loop through all the events and do the matchy/loopy thang foreach my $event ($p->events) { if (exists $event->{$key} and $event->{$key} =~ m!$re!i) { print "$event->{id}\n"; last; } } exit; # probably over kill to have this as a package but hey ho package DevInput::Parser; sub new { my $class = shift; return bless {}, $class; } # # Get Gerd Knorr's input utils from # http://dl.bytesex.org/cvs-snapshots/ # sub events { # not that we ever use this my $self = shift; # assumes lsinput is in your path my @lines = `lsinput 2>&1`; # loop, munge and frig my @events; my $cur = {}; for (@lines) { chomp; # skip blank lines next if m!^\s*$!; # match events that have nothing attached to them as well if (s!^open /!/! || m!^/!) { # if we already have an event, push it onto the list # and reset the event to be blank if (defined $cur->{id}) { push @events, $cur; $cur = {} } # set the current id (obviously) $cur->{id} = $_; next; } # trim s!^\s*!!; # split the key and value my ($key,$val) = split /\s+:\s+/, $_, 2; $cur->{$key} = $val; } # push the last event we found push @events, $cur if defined $cur->{id}; return @events; } 1;