in reply to glob a folder of images, and open text doc, find the matches and move the images.
my @line = $file; for (@line) { ...
This is basically just using $_ instead of $file. Is that really what you want to do? In fact, there are a lot of intermediate variables that could be removed to simplify the code. AFAICT, the following does exactly the same as the code you posted. See how much nicer of a SSCCE this is? If you edit your code down like this, I'll help us immensely, and it may even help you find the bug in the process.
#!/usr/bin/env perl use warnings; use strict; use File::Copy 'move'; my $findme = '/Volumes/photorepos/Perl/SLAperlDropback/'; chdir($findme.'2SLAday') or die "chdir: $!"; foreach my $file (glob "*.*") { open my $fh, '<', $findme.'dropback.txt' or die "open: $!"; while ( my $row = <$fh> ) { chomp $row; if ( $file =~ /$row/ ) { move( $file, $row ) or die "move: $!"; } } }
From this code, I see a couple of things:
If that's not the advice you're looking for, then please better explain the issue with the code, i.e. provide some short sample data and show the values of the variables using the debugging methods I mentioned above at different stages in the loop, explaining how they differ from what you expect.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: glob a folder of images, and open text doc, find the matches and move the images.
by flieckster (Scribe) on Feb 10, 2020 at 01:54 UTC | |
by haukex (Archbishop) on Feb 10, 2020 at 10:01 UTC | |
by flieckster (Scribe) on Feb 10, 2020 at 17:44 UTC | |
by haukex (Archbishop) on Feb 10, 2020 at 17:48 UTC |