I suspect the issue here is that your `ls` may be wrapping filenames in quotes if they have a space:
% ls -l drwxr-xr-x 2 hv hv 4096 Aug 10 2015 Desktop drwxrwxr-x 3 hv hv 4096 Sep 15 2020 'My Games'
On my system, I can get consistent results by adding "-Q" to the options, to have every filename quoted:
% ls -l -Q drwxr-xr-x 2 hv hv 4096 Aug 10 2015 "Desktop" drwxrwxr-x 3 hv hv 4096 Sep 15 2020 "My Games"
More generally, however, `ls` output is designed for humans, I would echo others' suggestions that you should use readdir() and stat() if you want reliable behaviour.
I'll note that you are also using (partially unanchored) pattern matching to compare the "new" list to the "old" list; that will also likely come to bite you eventually - better to clean up both lists and then do an equality check, which could be done fastest with a hash lookup:
my %OldFile; for my $file (@OldPicList) { $file =~ s{^\s+|\s+$}{}g; $oldFile{$file} = 1; } my @NewPicFolders; for my $file (@NewPicList) { $file =~ s{^\s+|\s+$}{}g; if ($oldFile{$file}) { # nothing } else { push @NewPicFolders, $file; } }
In reply to Re: Why can't I figure this out?????
by hv
in thread Why can't I figure this out?????
by JSAWS
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |