xjlittle has asked for the wisdom of the Perl Monks concerning the following question:

Hello gracious monks,

I am writing a script using the system() function in perl. When I run the script I get the following output:
bash-2.05# ./ch_sunflare-beam.pl You are on sunflare Which ACLs would you like to apply to /mkt/sbo/inbound rwx You said rwx /mkt/sbo/inbound 1: No such file or directory bash-2.05#

The directory certainly exists. If you would please look at my code and tell me where I have go awry:
#!/usr/bin/perl -w use strict; my @users = qw(ux43 ux95 ux61 ux10 ux78 vx14 ux26 vx20); my $users; my @dirs_sunflarebeam = "/mkt/sbo/inbound"; my $hostname = `hostname`; print "You are on $hostname\n"; print "Which ACLs would you like to apply to @dirs_sunflarebeam\n"; my $ans = <STDIN>; chomp $ans; print "You said $ans\n"; my @args = ("setfacl", "-m"); foreach my $dirs(@dirs_sunflarebeam){ print "$dirs\n"; <==this prints ok however the $dirs fai +ls below with the message posted above: system(@args, "u:$users[0]:$ans", "$dirs") == 0 or die "system @args failed $?"; # system(@args, "u:$users[3]:$ans", $dirs) == 0 # or die "system @args failed $?"; } my $dir = @dirs_sunflarebeam; #print "$dirs\n"; system("getfacl", "$dir");

Pleae let me know where my mistake is.
Thanks!
@gwadej
Ok my mistake. I misread where that error was coming from. However I still do not change the ACLs on the directory when I run the script:
bash-2.05# getfacl /mkt/sbo/inbound # file: /mkt/sbo/inbound # owner: mkt # group: mkt user::rwx user:ux10:rwx #effective:rwx user:ux438:rwx #effective:rwx user:pdev:rwx #effective:rwx group::rwx #effective:rwx mask:rwx other:rwx bash-2.05#

Replies are listed 'Best First'.
Re: Correct way to use system()?
by gwadej (Chaplain) on Aug 13, 2009 at 17:13 UTC

    You're problem has nothing to do with system. The problem is in these lines.

    my $dir = @dirs_sunflarebeam; #print "$dirs\n"; system("getfacl", "$dir");

    $dir contains the count of the items in @dirs_sunflarebeam, not the first item. The call to getfacl can't find a file named 1. You probably meant my $dir = $dirs_sunflare_beam[0];

    One minor nit: You don't need the quotes around $dir in the last statement. They really have no effect.

    Update: formatting correction.

    G. Wade
      I found it. I had an array # that I didn't want. Thanks for your help. I remove the "" as well.