chiark / gitweb /
New script to add up numbers on stdin.
[bin.git] / grep-services
1 #! /usr/bin/perl -ws
2 use strict;
3 use vars qw($f);
4
5 sub getservice ($)
6 {
7         (my $search) = @_;
8
9         open SERVICES, "/etc/services" or die "Couldn't open /etc/services";
10         while (<SERVICES>) { print if /\b\Q$search\E\b/; }
11         close SERVICES;
12 }
13
14 if ($f)
15 {
16         while (<>)
17         {
18                 chomp;
19                 getservice $_;
20         }
21 }
22 else
23 {
24         while (defined (my $arg = shift))
25         {
26                 getservice $arg;
27         }
28 }