Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: glob a folder of images, and open text doc, find the matches and move the images. by haukex
in thread glob a folder of images, and open text doc, find the matches and move the images. by flieckster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found