For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > July 2004 > QX









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author QX
Henk

2004-07-29, 3:55 am

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" );
}


Gunnar Hjalmarsson

2004-07-29, 3:55 am

Henk 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
Henk

2004-07-29, 3:55 am

Yes 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



Gunnar Hjalmarsson

2004-07-29, 3:55 am

[ 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>
[color=darkred]
>
> 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
Henk

2004-07-29, 3:55 am


"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.


Joe Smith

2004-07-29, 3:55 am

Henk 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com