I want to obtain names of owners of files, that are in specified directory (2 in the loops is just for testing, there are only 2 files in my /media anyways). So, if user's input is "/media", i get the following output:
sh: 2: /kuba: not found sh: 2: /sf_Shared: not found root:kuba
So it seems, that the script works, but displays "not found" anyways.
my $directory =<STDIN>; #"/media"; my @ls = qx(ls $directory); chomp @ls; my @fow; for(my $i = 0; $i < 2; $i++ ) { $fow[$i] = qx(stat -c '%U' $directory/$ls[$i]); #say $fow[$i]; } chomp @fow; print "$fow[0]:$ls[0]\n"; BTW, When I remove user's input and just declare $directory as "/media", it works perfectly fine.
$directorydata.my $directory =<STDIN>;will give you/media\n, without stripping\nyour OS will not find the directory.chomp()to remove the newline from data read from<STDIN>is, in general, a very good idea. But in this case, it's not necessary as the string (with the newline attached) is passed toqx(ls $directory). And the shell that executes the command doesn't care that there's a newline on the end. Tryperl -lE '$dir = ".\n"; say qx(ls $dir)'