Hi Monks,
I have been banging my head against the wall for hours with this, I am using this method in multiple places but somehow it does not work here...
Here is the logic:
I comapre 2 files (OldPicList and NewPicList) and if values are found in NewPicList only then the relevant dir should be read and the contents written to a file (filenames only).
All is generally well, except if the filenames have spaces in them....
example the following list will only print the first 7 items to the file
20141025_211155b.jpg
20141028_140739b.jpg
20141101_160837b.jpg
20141101_160839b.jpg
20141101_160856b.jpg
20141102_112335b.jpg
Screenshot_from_2021-02-04_17-38-07.png
Screenshot from 2021-02-04 19-13-44.png
Screenshot from 2021-02-05 08-59-49.png
Screenshot from 2021-02-09 11-48-40.png
Screenshot from 2021-02-09 15-46-23.png
Screenshot from 2021-02-10 09-46-34.png
Screenshot from 2021-02-11 10-06-13.png
Screenshot from 2021-02-15 14-52-40.png
What puzzles me is that when I print the @array to STDOUT before the FH the output is correct and contains all files (the file list above is the printout of the array, there seems to be an extra char at the end of every line, this might be the issue?
completely puzzled..... any help would be greatly appreciated!
J
foreach $a (@NewPicList)
{
chomp($a);
$a =~ s/^\s+//;
if (grep(/$a\s+$/, @OldPicList))
{
}
else {
push @NewPicFolders, "$a";
}
}
foreach $b (@NewPicFolders) {
open (RD, "ls -l /dir1/dir2/dir3/'$b' |");
binmode RD, ':encoding(UTF-8)';
while (<RD>) {
push @user_dir, $_;
}
close(RD);
s{^\s+|\s+$}{}g foreach @user_dir;
foreach $fileline (@user_dir)
{
@filenames = split(/\s+/,$fileline, 9);
unless (@filenames[8] eq "")
{
$filenames[8] =~ s/\s+/_/g;
push @PicList, "$filenames[8]\n";
}
}
print "PICLIST: @PicList";
open(FH, '>', "/dir1/dir2/dir3/$b.folder") or die $!;
print FH "@PicList";
close FH;
@PicList = ();
@user_dir = ();
@filenames = ();
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.