develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [ID 20010821.002] bug in getpwnam

Thread Previous | Thread Next
Dave Mitchell
August 21, 2001 09:06
Re: [ID 20010821.002] bug in getpwnam
Message ID:
Carsten Grohmann <> wrote:

> I want to change the owner of a file by using the following command:
>   chown (getpwnam ($username))[2], (getgrnam ($groupname))[2], 
> $destfile;
> and I get an syntax error near )[.

Your problem is that Perl is interpreting the '(' following the chown
as the start of a call to the function chown(). You can fix this
by either giving a real pair of parantheses for the function call,
or by starting the first argument with something other than '(', eg

chown( (getpwnam ($username))[2], (getgrnam ($groupname))[2], $destfile);
chown +(getpwnam ($username))[2], (getgrnam ($groupname))[2], $destfile;

Dave M.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About