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
    Or just
    foreach my $fileline (<$dir/*>) { }

    since globbing already removes dotfiles and includes the path.

    Personally, I'd use Path::Tiny or Path::Class before touching opendir.

Re^2: Why can't I figure this out?????
by JSAWS (Novice) on Aug 31, 2022 at 11:44 UTC
    true... true.... I use this method multiple times.... sometimes I need info from the other fields :)

      Instead of worrying about whitespace in filenames and proper quoting etc. , I can only recommend using readdir for the filename and stat for the other fields.

        Thx Corion

        Changed the code accordingly but same results.....