Of course it is possible to do the fitlering. But you haven't given us any indicatioin of the sort of filtering you want so it is difficult to give any sort of a helpful reply.
The easiest way might be to replace your map() with an explicit for-loop and process the data one line at a time. Non-trivial map() sequences tend to be rather opaque when you come back to the later.
On 29-Jul-2002 Douglas Willis wrote:
Hi,
A quick question about filtering input in perl.
I have a little program that reads the output of the w command into a hash. It the sorts the records and outputs the results. What I would like to do is filter the initial read on <WHO> so that the only records in the hash are people with an idle time in days.
Is it possible to put a construct in the @Who_Data = <WHO>; so that all the filtering is done in one hit?
The code so far is.
#!/usr/bin/perl
open(WHO,"w -h |"); @Who_Data = <WHO>; my @sorted = map { $_->[0] } sort custom map { [$_, split /:/ ] } @Who_Data;
print @sorted;
sub custom { $a->[0] cmp $b->[0]; }
-- Douglas Willis (ddw@nerc-bas.ac.uk) British Antarctic Survey High Cross, Madingley Road Cambridge, CB3 0ET, United Kingdom tel: +44 1223 221400, fax: +44 1223 362616
main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!