in reply to Why can't I figure this out?????
open (RD, "ls -l /dir1/dir2/dir3/'$b' |"); ... foreach $fileline (@user_dir) { @filenames = split(/\s+/,$fileline, 9);
Consider using opendir and readdir (or even File::Find) there, instead of reading from ls -l. If all else fails, consider using ls -1 at least so you only get a single filename per row, instead of having to parse and split things.
The following could give you a start:
my $dir = "/dir1/dir2/dir3/$b"; opendir my $dh, or die "Couldn't read directory '$dir'"; my @user_dir = map { "$dir/$_" } grep { $_ !~ /^\.\.?$/ } readdir $dh; ... foreach my $fileline (@user_dir) { my $filename = $fileline; ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why can't I figure this out?????
by NERDVANA (Priest) on Aug 31, 2022 at 21:51 UTC | |
|
Re^2: Why can't I figure this out?????
by JSAWS (Novice) on Aug 31, 2022 at 11:44 UTC | |
by Corion (Patriarch) on Aug 31, 2022 at 11:45 UTC | |
by JSAWS (Novice) on Aug 31, 2022 at 12:30 UTC |