Code Comments
Programming Forum and web based access to our favorite programming groups.Hello all,
I am trying to fine tune my perl code here.
Now i am using just an systemcall to addusers but i've found out " q x` ` "
but i don't know how to add qx to the code below perhaps there is anyone
here to tell me how to ?
sub createuser(@) {
$username = shift;
$pwd = shift;
system("adduser -g webusers -p $pwd -d $Userpath/$Domainname
\L$username\U");
chmod( 0750, "$Userpath/$Domainname" );
}
Post Follow-up to this messageHenk wrote:
> I am trying to fine tune my perl code here.
>
> Now i am using just an systemcall to addusers but i've found out
> " q x` ` " but i don't know how to add qx to the code below
> perhaps there is anyone here to tell me how to ?
>
> sub createuser(@) {
> $username = shift;
> $pwd = shift;
>
> system("adduser -g webusers -p $pwd -d $Userpath/$Domainname
> \L$username\U");
> chmod( 0750, "$Userpath/$Domainname" );
> }
The qx// operator (or backticks) is explained in "perldoc perlop". Is
there anything there you don't understand?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Post Follow-up to this messageYes there is take the system("adduser blahblah");
should this be qx`("adduser blahblah")`; ???
and chown ? how must i do that ?
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2mka04FnpkgaU1@uni-berlin.de...
> Henk wrote:
>
> The qx// operator (or backticks) is explained in "perldoc perlop". Is
> there anything there you don't understand?
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
Post Follow-up to this message[ Please type your replies below the quoted part of the message you
respond to. Please do not quote the whole message, but only what's
appropriate to give context. ]
Henk wrote:
> Gunnar Hjalmarsson wrote:
<code snipped>
>
> Yes there is take the system("adduser blahblah"); should this be
> qx`("adduser blahblah")`; ???
It should be e.g.
my $output = qx(adduser blahblah);
or
my $output = `adduser blahblah`;
i.e. don't surround the system command with doublequotes.
> and chown ? how must i do that ?
There is a built-in chown() function in Perl
perldoc -f chown
You probably need to run the program as root to be able to change file
ownership.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Post Follow-up to this message"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message news:2mkb6aFni458U1@uni-berlin.de... > [ Please type your replies below the quoted part of the message you > respond to. Please do not quote the whole message, but only what's > appropriate to give context. ] > > Henk wrote: > > <code snipped> > > > It should be e.g. > > my $output = qx(adduser blahblah); > > or > > my $output = `adduser blahblah`; > > i.e. don't surround the system command with doublequotes. > > > There is a built-in chown() function in Perl > > perldoc -f chown > > You probably need to run the program as root to be able to change file > ownership. > > -- > Gunnar Hjalmarsson > Email: http://www.gunnar.cc/cgi-bin/contact.pl Ah Thank you. I think i understand now.
Post Follow-up to this messageHenk wrote:
> Now i am using just an systemcall to addusers but i've found out " q x` `
"
> but i don't know how to add qx to the code below perhaps
The useradd command does not produce any output, therefore using qx
will not be of any advantage.
Use system("command") if command interacts with the terminal.
Use $results=qx'command' to send output from command to a variable.
-Joe
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.