Porting Shell to Perl must be done mindfully of simpler ways to achieve the same thing. It is ineffective to use `cat | grep` multiple times, when you could simply read the file in and print out the lines that you are interested in one by one.
For example; and this will still not quite do what you want, which is no doubt to retrieve all active aliases entries for a given site. You will also need to consider /etc/mail/virtusertable if present on your system.
#!/usr/bin/perl -w use strict; use constant MAIL_ALIASES => "/etc/mail/aliases"; my $site = shift; # all users of a site have home directories under # /home/sites/XXX/users/. my @users = (map { m{/([^/]*)$} } # `basename' with a RE (grep { -d $_ } # only directories </home/sites/$site/users/*> # glob )); # build a big regular expression with each user name; # use \b to anchor the pattern match, so that a user called # `jane' won't show up entries for `janet' my $pattern = '\b(' . join("|", @users) . ')\b'; open ALIASES, MAIL_ALIASES or die("Failed to open ".MAIL_ALIASES."; $!"); while (<ALIASES>) { print if m/$pattern/o; } close ALIASES;
In reply to Re: Error in converted shell script (was: Pls Help)
by mugwumpjism
in thread Error in converted shell script (was: Pls Help)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |