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:
- Unless what's in dropback.txt are regular expressions, you probably should say /\Q$row/ (see quotemeta).
- You don't show the contents of dropback.txt. Since $file will probably be plain filenames, if $row is a full pathname, note that if you're checking whether $row contains $file, you've got the regex reversed, and it should be $row =~ /\Q$file/, perhaps with an anchor or other things to prevent it from accidentally matching a string that's just part of a pathname. Or, even better, you already loaded File::Basename but didn't use it - use its fileparse to strip the pathname off, and then do a plain eq on the filenames.
- You use chomp in several places where it isn't needed. If you're worried about excess whitespace, see the corresponding points in the Basic debugging checklist - use either Data::Dumper with $Data::Dumper::Useqq=1;, or use Data::Dump.
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.
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.