2010年5月19日星期三

[PerlChina] 一个朋友的问题,实在没看明白啥意思,大伙看看

I want to use @ARGV and not <>. So I want to run the script with the same
functionality as below (userA mapped to userB's .profile and or userA mapped
to userB's profile and userC mapped to userD's .profile and or userE and
userF mapped to userG's .profile) like:

$ perl script -userA -userB

or $ perl script -userA -userB -userC -userD

or $ perl script -userE -userF -userG

as opposed to $ perl script then typing in the userA userB, CNTRL-D, userC
userD

thanks!

#!/usr/bin/env perl
use strict;
use warnings;

my (%adds, $user, $muser,);

LOOP:while (<>) {
chomp;
($user, $muser) = map lc, split;
if ( s/[a-z]//g <= 5 ) {
print uc("\nyou must enter at least 6 characters, try again!!!??
+?\n\n");
goto LOOP;
}
else {

if ( -d "/users/$muser" ) {
$adds{$user} = qx(ls /users/$muser/.profile);
}
elsif ( -d "/home/$muser" ) {
$adds{$user} = qx(ls /home/$muser/.profile);
}
else {
print "\n$muser does not have a /users subdir,
exiting!\n\n";
exit 0;
}

print uc("\nnow building user associations for your
user-adds!\n");

while ( my ($key, $val) = each(%adds) ) {
print "\n$key will have a profile of $val\n";
chomp ($key,$val);
if ( ! -d "/users/$key" ) {
system("mkdir /users/$key");
system("chown $key:users /users/$key");
system("ln -sf $val /users/$key/.profile");
}
}
}

--
您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 perlchina+unsubscribe@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。

没有评论: